Parametric Inner Class Work-Around 
Java Layers Home

JL Download

Installation Notes

Release Notes

Quick Reference

Code Generation


The example code below describes the work-around necessary for using parametric inner classes in JL.

Here's the code for file C8.jl, which contains a description of the work-around.  (There's only two lines of code in the class, but if the comments wrap in your browser, things look much worse.)

// The Release Notes for JL v0.21a describes why JL's current implementation
// doesn't handle non-static inner class instantiation. This example
// describes a work-around solution to this problem for the brave programmers.
// The work-around goes as follows:
// 1.Write the JL source code in a way that allows jlc to compile to
// ALMOST correct Java source code.
// 2.Invoke jlc with the "-keepjava -nojavacomp" compile options.
// 3.Perform a simple hand edit of the generated code so that it becomes
// legal Java code.
// 4.Invoke javac for the fixed up Java source code.
// The example below explains exactly what the JL code should look like
// and how it should be edited to yield legal java code.
// Good luck. As soon as I get some time, I'll enhance JL to resolve
// parametric type instantiations inside all expressions.
// Rich
class C8
 // Driver.
 public static void main(String args[])
  // Instantiate outer class and create object.
  D8<int> d8 = new D8<int>();

  // Give JL what it needs first. The full qualification of Inner after
  // the new keyword allows JL to find the nested class. JL currently
  // doesn't interpret "" because d8 is a field reference. 
  D8<int>.Inner<String> in = D8<int>.Inner<String>();;

  // The last line of code will generate the following code in file
  // D8_43057E.Inner_BA042DE in = D8_43057E.Inner_BA042DE();
  // This is ALMOST correct Java source code. Java is well aware of
  // what "" means, so full qualification of Inner_BA042DE won't
  // work. Replace the above generated line of code with one that
  // erases the full qualification of the second occurrence of Inner:
  // D8_43057E.Inner_BA042DE in = Inner_BA042DE();
  // This is legal Java. Enter "javac" to compile.


Here's the code in file D8.jl, which is referenced by C8.

class D8<T>
 T t;

 // Non-static nested class.
 class Inner<U> {U u;}

Last Modified:  08/27/2001 11:21 AM