'This' type

Neal Gafter neal at gafter.com
Tue Mar 3 12:25:54 PST 2009


I'd love to see the specification, in particular the subtyping rules
and modifications to type inference.  Once those are in place, I'd
like to see an argument that this feature leaves the generic type
system sound (i.e. there are no ClassCastExceptions unless there are
casts or warnings in the source code).  As described in
http://blogs.sun.com/darcy/entry/guidance_measure_language_change_size
almost any type system change is likely out of scope for project coin.

On Tue, Mar 3, 2009 at 12:17 PM, Marek Kozieł <develop4lasu at gmail.com> wrote:
> AUTHOR: Lasu aka Marek Kozieł http://lasu2string.blogspot.com/
>
> OVERVIEW
>
> FEATURE SUMMARY:
> This type add ability to project valid interfaces(classes) for further
> extending/implementing. 'This' means current interface/class type or
> something implementing/extending it.
>
>
>
> MAJOR ADVANTAGE:
> - Support of interface projecting at interface level.
> - More readable code structure (interfaces/methods).
> - Making refactor more enjoyable (much easier).
> - Discarding request of replacing 'void' with 'this'.
> - Splitting interfaces to sub-interfaces can become pleasant.
> - Down casting working properly.
> - Decreasing number of method signatures in classes/interfaces.
>
>
> MAJOR DISADVANTAGE:
> - Class 'This' may already exist somewhere in code(?)
> - As so far, it's not been thought over know if there is point of using it
> for input parameters.
> - 'This.class' might be a problem for generics, but generally everything
> depends on how 'This' is interpreted(personally, I think that it should be
> generic with arguments)(this.getClass()).
>
> ALTERNATIVES:
> Rewriting each method's signature on every class / interface.
>
> EXAMPLES
>  public static interface IB implements Iterable<This> {
>  }
>
>  public static interface IC implements IB {
>  }
>
> Would mean(which is impossible now time):
>  public static interface IC implementsIB, Iterable<IC> {
>  }
>
> public static interface IA {
>  This write(String s);
>  }
>
>  public static interface IB extends IA {
>  This write(double value);
>  }
>
>  public abstract static class CC implements IB {
>  This write(int value){
> __  ...
> __  return this;
>  }
>  }
>
>  public static class CD extends CC {
>  @Override
>  public This write(double value) {
> __  ...
> __  return this;
>  }
>  @Override
>  public This write(String s) {
> __  ...
> __  return this;
>  }
>  }
>
>  public static void main(String[] args) {
> __  CD object = new CD();
> __  object.write("Some").write(3).write(3.11);
>  }
>
>
> Nowdays, the same code would look as:
> public static interface IA {
>  IA write(String s);
>  }
>
>  public static interface IB extends IA {
>  IB write(double value);
>  @Override
>  IB write(String s);
>  }
>
>  public abstract static class CC implements IB {
>  CC write(int value){
> __  ...
> __  return this;
>  }
>
>  @Override
>  public abstract CC write(double value);
>
>  @Override
>  public abstract CC write(String s);
>  }
>
>  public static class CD extends CC {
>  @Override
>  public CD write(double value) {
> __  ...
> __  return this;
>  }
>  @Override
>  public CD write(String s) {
> __  ...
> __  return this;
>  }
> __  @Override
>  CD write(int value){
> __  ...
> __  return this;
>  }
>  }
>
> DETAILS:
>
> SPECIFICATION:
> (I did not have time to analyze this completely.)
>
> COMPILATION:
> With 'This' type is valid:
> this
> null
> ? extends This
>
> 'This' should be considered to be able to appear in:
> return type(yes).
> input type(yes/no?).
> method body(yes?).
> As generic parameter(yes/only if they appear as return types?).
>
> List<This extends Container<This>> would mean This but not less than
> Container
>
> This could be reduced to last superclass
>
> COMPATIBILITY
>
> Only programs where are class/interface named 'This' used can be problem.
>
> REFERENCES
>
> Notice that considered document does not contain complete analyze of those
> solutions and can have some lacks. So if you have some questions/advices
> that it does not fully fit with Project Coin, post it on my blog to discuss:
> http://lasu2string.blogspot.com/2009/03/this-type.html
>
>
> --
> Pozdrowionka. / Regards.
> Lasu aka Marek Kozieł
>
> http://lasu2string.blogspot.com/
>
>



More information about the coin-dev mailing list