I agree with Jess, non-public methods and static methods (with
implementations) would be handy. Also the Scala technique of allowing
fields that are replaced by methods, hence properties, would be great,
e.g.:
interface X { // Assuming keyword interface now meant trait!
int x = 1; // Field
}
was a shorthand for:
interface X { // Field replaced by methods
int getX();
int setX( int x );
int initX() { return 1; } // Note method body
}
which in turn was a shorthand for:
interface X { // Current Java
int getX();
int setX( int x );
int initX();
class Trait { // Method bodies from trait
static int initX( X self ) { return 1; }
}
class Default implements X { // Default X class for when no further
inheritance needed
public int x = initX();
public int getX() { return x; }
public int setX( int x ) {
this.x = x;
return x;
}
public int initX() { X.Trait.initX( this ); }
}
}
and the compiler translated:
X x = new X();
x.x = 2;
into:
X x = new X.Default();
x.setX( 2 );
On Nov 5, 3:42 pm, Jess Holle <[EMAIL PROTECTED]> wrote:
> I concur. Traits would be a hugely useful addition.
>
> To make them really sing, however, one needs non-public interface
> methods. For instance:
>
> public interface Foo
> {
> public void doIt()
> {
> // default implementation logic implemented in terms of
> getXInternal() and/or setXInternal()
> }
>
> protected X getXInternal();
> protected void setXInternal(X x);
> }
>
> Either that or one needs to allow interfaces to have fields, which is
> much uglier. Having non-public accessors allows one to have virtual
> fields used in the default logic which can then be mapped as appropriate
> as part of implementing the trait interface.
>
> --
> Jess Holle
>
> Mark Derricutt wrote:
> > Please please please bring on traits! I'm somewhat on the fence of
> > rather seeing traits than closures in java sooner than the other.
>
> > I'm finding LOTS of places in my code where traits would just make
> > things cleaner.
>
> > More and more I think I just want scala :)
>
> > On Wed, Nov 5, 2008 at 12:15 PM, hlovatt <[EMAIL PROTECTED]
> > <mailto:[EMAIL PROTECTED]>> wrote:
>
> > I thinks that Traits are a great idea for Java and judging by #215 the
> > posse, particularly Dick, like them. I wrote about them for Java 7 in:
>
> > http://www.artima.com/weblogs/viewpost.jsp?thread=220916
>
> > What do you think?
>
> > --
> > "It is easier to optimize correct code than to correct optimized
> > code." -- Bill Harlan
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---