On Dec 16, 2007 7:40 PM, hlovatt <[EMAIL PROTECTED]> wrote:
>
> I am interested in adding Traits to the Java language. Briefly Traits
I think Scala might have beaten you to it... :-)
> are like interfaces but you can have method bodies, but no
> constructors or fields. If there is a conflict you have to resolve the
> conflict:
>
> interface X { int m() { return 1; } }
> interface Y { int m() { return 2; } }
> class XY implements X, Y { // conflict - 2 m methods
> public int m() { return X.m(); } // resolve conflict - otherwise
> error
> }
>
> More info. at: http://www.artima.com/weblogs/viewpost.jsp?thread=220916
>
> This is easy (well if you call modifying the compiler easy) if you
> force recompilation. However it would be an advantage to allow Traits
> to be extended without recompilation since at present an interface is
> in effect a fixed entity, e.g. change X:
>
> interface X {
> int m() { return 1; }
> String s() { return "A"; }
> }
>
> Ideally you wouldn't want to have to recompile XY, instead it would be
> nice if the class loader automatically added method s to XY (assuming
> that XY didn't have an s already).
>
> Does anyone have any wisdom they are willing to impart on the
> practicality of writing a custom class loader or modifying *the* class
> loader to achieve this?
Would implementing this via delegation to static methods not be a much
lighter way of achieving this? Essentially using the standard
extension method hack of treating the first argument as 'this', but
providing method bodies in the implementing classes which do that
delegation, so they can be overridden properly, appear in the normal
class hierarchy, etc.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM
Languages" 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/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---