Hacker News new | ask | show | jobs
by elmarschraml 3997 days ago
If you're looking for a REPL for Java, try the Groovy shell (comes standard with an install of Groovy).

Meant, as the name implies, for Groovy, but since Java is a subset of Groovy, works fine for any Java code, too.

It's great for quickly trying out an API or library. Also makes it easy to just drop a bunch of jar files onto the classpath.

3 comments

> Java is a subset of Groovy

Java is not a subset of Groovy. Some syntax valid in both will behave differently in each, e.g. default visibility, and how == behaves.

Can second this. At work, we have a large legacy Java codebase, and our most useful ops tool is our entire codebase and Spring beans loaded into a Groovy shell. Extremely convenient. Groovy is largely compatible with Java, but it also has shorthand notations (splat operator, elvis operator, closures, optional typing) and collections that are much more expressive than Java.
What about, for instance, the difference in multi-methods presented here? I would assume you would get different results in the Groovy REPL than in a Java compiler.

http://www.groovy-lang.org/differences.html