Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Java - Typless
Java
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
src
.gitignore
README.markdown
build.xml

README.markdown

jTypeless - Java, but actually Groovy

This sample project is inspired by typelessj work, by Michael Bayne and Michael Ernst.

This is a proof-of-concept implementation that treats Java code like a Groovy code (with taking care of some edge cases), with ignoring all the types!

This sample code illustrates few points:

  1. You can use an annotation processor to invoke a different specialized (dynamic?) compiler, without affecting the usability of the tool

  2. how you can compile Groovy but ensure the code is syntactically valid Java code

  3. how you can generate Groovy transformations (not done yet)

Unfortunately, there are some rough edges here, but hey, this worked within less than two hours of work.

Sample:

Consider the following class:

[Available in jtypeless/examples/Sample.java]

class Sample {
    private void test(Integer a) { System.out.println("Int: " + a); }

    public static void main(String[] args) {
        String s = 1 + 3;
        new Sample().test(s);
        s += 3;
        new Sample().test(s);

        Object a = new Sample();
        a.test(3);
    }
}

Needless to say this program is an invalid Java program. However, you can still compile it and run it with jTypeless.

Steps:

  1. Checkout the code

    git clone git://github.com/notnoop/jtypeless.git
    
  2. Build jtypeless

    cd jtypeless
    ant
    
  3. Compile Sample.java and run it

    cd examples
    javac -cp ../jtypeless.jar Sample.java
    java -cp ../jtypeless.jar:. Sample
    
  4. Verify the results:

    Int: 4 Int: 7 Int: 3

NOTE: This only works with Java 6, not Java 7

Something went wrong with that request. Please try again.