Posts

Showing posts from June, 2012

Self-types in NRoles

Since roles are weaved into target classes, it's sometimes necessary for them to be able to identify the type of these classes. NRoles supports self-types through the use of a type parameter with the special name S : public abstract class REquatable<S> : IEquatable<S>, Role { public abstract bool Equals(S other); public bool Differs(S other) { return !Equals(other); } } To cast this to the type parameter, just use the Cast<T> extension method: public class Identity<S> : Role { public S Self { get { return this.Cast<S>(); } } } When other roles compose roles with self-types, they must flow the self-type through, since it will ultimately be determined by the target classes that compose them: public abstract class RComparable<S> : IComparable<S>, Does<REquatable<S>>, Role { ... } The post-compiler will check all classes that compose roles with self-types and issue an error message if the typ...

Java 8 virtual extension methods are begging to be free of interfaces

To cope with API evolution and to provide new extensions for lambda-friendly methods, Java 8 will introduce a form of extension methods in interfaces (which were called public defender methods in previous iterations of the proposal). Interface methods will be allowed to have bodies (or just a reference to a static method): interface MyInterface { void method() default { System.out.println("A good idea?"); } } A class implementing MyInterface doesn't need to provide an implementation for method() . This is particularly valuable for interface evolution to maintain binary compatibility with classes already compiled with the old interface version. In general, the old binaries would work with the new defaulted interface method without recompilation; it will just use the default implementation. The default keyword is a deliberate choice not to conflict with the rule that "interfaces have no code". Now they can have default code. Conflict resolution...