'This' type (original) (raw)

Marek Kozieł develop4lasu at gmail.com
Tue Mar 3 12:17:17 PST 2009


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:

MAJOR DISADVANTAGE:

ALTERNATIVES: Rewriting each method's signature on every class / interface.

EXAMPLES public static interface IB implements Iterable { }

public static interface IC implements IB { }

Would mean(which is impossible now time): public static interface IC implementsIB, Iterable { }

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> 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