Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand well, you would like to be able to generate new class/type through a transformation of an existing type. Something like</p> <pre><code>class Synchronized&lt;T&gt; { Object invocation( Object ... args ) { synchronize( this ) { return original.invocation( args ); } } } ... Foo f; Synchronized&lt;Foo&gt; f2; f.bar(); f2.bar(); // would be valid for the type-system </code></pre> <p>, where <code>invocation</code> and <code>original</code> would be keywords for this novel abstraction. </p> <p>The new type can be seen as a <strong>proxy</strong> / <strong>wrapper</strong> / <strong>adapter</strong> around the original type. Whether the new type still represent a subtype of the original or not is then another question. How far the abstraction would support changing the return type is also another question.</p> <p>While byte code instrumentation, AOP or custom class loader could achieve part of this, I would say that in spirit the closest match is a dynamic proxy. The code of a dynamic proxy looks indeed terrible similar to what I wrote above. <a href="https://stackoverflow.com/questions/1935178/correct-usage-of-stateful-beans-with-servlets/1935476#1935476">Here</a>, <a href="https://stackoverflow.com/questions/2646510/how-to-use-aop-to-intercept-a-method-call-in-super-on-an-argument/2646760#2646760">here</a> and <a href="https://stackoverflow.com/questions/2587702/using-dynamic-proxies-to-centralize-jpa-code/2817478#2817478">here</a> are situations I solved with dynamic proxies. Of course dynamic proxies are not static but as the name says, dynamic. </p> <p>I fear that the general problem that you describe -- how to create variations of existing types -- is too broad. Proposition of type system extension have been made for specific situations, e.g. how to create an adapter from interface X to Y so that all concrete implementation of X can also be seen as implementation of Y. </p> <p>Maybe have a look at these papers (I haven't read them all yet, but I plan to):</p> <ul> <li><a href="http://portal.acm.org/citation.cfm?id=679857" rel="nofollow noreferrer">Generic Wrappers</a></li> <li><a href="http://portal.acm.org/citation.cfm?id=1244242" rel="nofollow noreferrer">Featherweight wrap java</a></li> <li><a href="http://portal.acm.org/citation.cfm?id=679712" rel="nofollow noreferrer">Type-safe delegation for Java</a></li> <li><a href="http://homepages.cwi.nl/~ralf/JavaGI/" rel="nofollow noreferrer">JavaGI</a></li> <li><a href="http://portal.acm.org/citation.cfm?id=1167477" rel="nofollow noreferrer">Statically scoped object adaptation with expanders</a></li> <li><a href="http://portal.acm.org/citation.cfm?id=1167485" rel="nofollow noreferrer">Uniform Proxies for Java</a></li> </ul> <p>For the last one, the abstract says:</p> <blockquote> <p>We discuss the precise benefits and costs of our extension in terms of the criteria introduced, and illustrate the usefulness of uniformly available proxies by implementing future method invocations both safely and transparently.</p> </blockquote> <p>, which was one of your question.</p> <p>Cool question btw, I wish a general solution to your problem exist. I don't pretend to be an expert in the subject, so there might even be one, but I'm not aware of.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload