JShell API questions / feedback

Roy van Rijn roy.van.rijn at gmail.com
Tue Jan 26 14:28:14 UTC 2016

Dear kulla-dev's,

I've been working on a project to incorporate the JShell API into an
environment to help teach the Java language to absolute beginners
(mainly kids).

For this I'm using the JShell API and making my own editor. The eval()
results have to be parsed and evaluated by my code. But I've ran into
a few issues (or maybe just questions).

First, I need to process the Snippet output. One thing I've noticed is
that the Snippet API is rather limited. Image you create a method and
receive a MethodSnippet. Now I want to know the return type of this
method for further processing, how do I get to this? The only thing
I've currently found is:

MethodSnippet snippet = ...;
String returnType =
snippet.signature().substring(snippet.signature().lastIndexOf(')') +

Do I have to parse the signature myself to get to the return type?
This seems rather odd. Also, in the API there seems to be a lot of
String-usage. Instead of returning the actual type everything is a
String. I think I'd rather love to see the API returning classes and
objects. For example the 'value' of something that has been evaluated
now is always a String (the toString() of the object is called)
instead of the actual object. I'd rather have the API returning the
object and the JShell terminal calling toString() on it for display
purposes. Would this be possible? IMHO that would be a much better
API. The same si true for the mentioned returnType, I'd love to have
it return a class instead of a string.

Also, one other thing I've noticed is that the method names used in
the API are not following the bean-spec, for example to get fields
from a snippet you have to call snippet.name() and snippet.typeName().
This seems very odd compared to most Java JDK code. I would have
suspected snippet.getName() and snippet.getTypeName(). Is this a new
preferred way of writing methods in a JDK API? Will we see this in
other API's as well? Call me old-fashioned but I personally rather
just have the getters.

I'd love to hear what other people think about the current API design,
am I the only one bothered by this? Or am I using it the wrong way, or
missing the point?


More information about the kulla-dev mailing list