val st = new StringTokenizer(str = s, delim = x, returnDelims = true)
vs:
val st = new StringTokenizer(s, x, true)
The former is more readable but does not compile.
Note: I think Java 8 can emit param names now (with the -parameter
option) so we can atleast support this for the JDK libs, local Java sources and any other external Java library compiled with the -paramter
option: https://docs.oracle.com/javase/tutorial/reflect/member/methodparameterreflection.html
4 Likes
Yes, in scala/scala#4735 Simon already implemented emitting them. I agree the logical next step is to also read them from javac-produced classfiles and let you specify them.
lrytz
April 27, 2017, 6:31am
4
We have that already
> cat A.java
public class A {
public static int flup(int fancy) { return fancy + 1; }
}
> javac -parameters A.java
> scala -version
Scala code runner version 2.12.2 -- Copyright 2002-2017, LAMP/EPFL and Lightbend, Inc.
> scala -e 'println(A.flup(fancy = 33))'
34
>
1 Like
lrytz
April 27, 2017, 2:09pm
6
I’m not sure what you mean - it should work for all java libraries that were compiled with -parameters
. Unfortunately the Java standard library is not compiled with that flag, as far as I can tell
> unzip -d . -j /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar java/lang/String.class
> javap -v -classpath . String | grep MethodParameters -C 2
Warning: Binary file String contains java.lang.String
>
> javap -v -classpath . A | grep MethodParameters -C 2
#8 = Utf8 flup
#9 = Utf8 (I)I
#10 = Utf8 MethodParameters
#11 = Utf8 fancy
#12 = Utf8 SourceFile
--
--
LineNumberTable:
line 2: 0
MethodParameters:
Name Flags
fancy
>