2

I am attempting to add a feature to Java. You can find a description of it here. I was wondering if there is a way to write a custom Java compiler (or an extension for the compiler). The code would still compile into standard Java code, so I wouldn't need a custom JVM (or JRE, whichever it is). If anyone knows of how to do this, let me know. If you know it's not possible, could you link me to proof (maybe a statement from Oracle)? Thanks!

13
  • scala-lang.org Commented Aug 6, 2014 at 0:30
  • @univerio Scala would allow me to do this? Can you provide a link to a tutorial or sample class or anything at all? Commented Aug 6, 2014 at 0:32
  • openjdk.java.net/groups/compiler Commented Aug 6, 2014 at 0:33
  • Sorry, it was a tongue-in-cheek observation that it's much easier to use a mature language that somebody else has already written with the features you want than to fork javac. Commented Aug 6, 2014 at 0:34
  • @univerio My idea is not implemented in any language that currently exists. Commented Aug 6, 2014 at 0:34

2 Answers 2

3

Scala targets the JVM and its Structural Typing does what you want. Example:

def generateNickname(name: {def getName(): String; def setName(name: String): Unit}): String {
  // ...
}
Sign up to request clarification or add additional context in comments.

Comments

0

The Eclipse Compiler for Java (ECJ) is open source, so it's freely modifiable. See the JDT Core documentation. However, @univerio's suggestion to look at Scala before taking this on is a good idea. Scala fixes many of the shortcomings of Java but still compiles to JVM code, so existing Java libraries work seamlessly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.