You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an entry point wrapper that looks something like the trait listed below that is intended to expose a main for a java entry point if type T = Unit or an arbitrary return type T if the module is embedded:
Unfortunately, I get this bytecode from the compiler (the same for both 2.8.1 and 2.9.0.1):
$ javap A
Compiled from "test.scala"
public final class A extends java.lang.Object{
public static final java.lang.Object main(java.lang.String[]);
public static final void run(java.lang.String[]);
}
Why do I get a return type of java.lang.Object, in this case, for main()? How do I get void in this scenario so that java will allow my to use A as an entry point?
$ javap B
Compiled from "test.scala"
public final class B extends java.lang.Object{
public static final void main(java.lang.String[]);
public static final void run(java.lang.String[]);
public static final java.lang.Object main(java.lang.String[]);
}
So it seems override didn't override anything and the compiler doesn't complain or warn about this. Is this a boxing issue?
The text was updated successfully, but these errors were encountered:
The return type of Object in RunWrapper is correct. This is how generics work.
Unless we special case main, you will have to write a method which is specifically Unit, you can't use a generic implementation because the jvm requires the exact signature.
When I first saw the example I thought there was a bug, but now if there is one I don't know what it is, other than that we should spot a method which looks like it's trying to be an entry point and warn that it is not in fact an entry point.
s wade (swadenator) said:
I'm guessing that object B is the bug. Shouldn't the override yield a warning or an error instead of quietly creating a main method with a void return type in addition to the base class's main?
I have an entry point wrapper that looks something like the trait listed below that is intended to expose a main for a java entry point if type T = Unit or an arbitrary return type T if the module is embedded:
Unfortunately, I get this bytecode from the compiler (the same for both 2.8.1 and 2.9.0.1):
$ javap A
Compiled from "test.scala"
public final class A extends java.lang.Object{
public static final java.lang.Object main(java.lang.String[]);
public static final void run(java.lang.String[]);
}
Why do I get a return type of java.lang.Object, in this case, for main()? How do I get void in this scenario so that java will allow my to use A as an entry point?
However, if I define the following:
object B extends RunWrapper[Unit] {
def run(args : Array[String]) { println("the end") }
override def main(args : Array[String]) { try { run(args) } finally { } }
}
I get this:
So it seems override didn't override anything and the compiler doesn't complain or warn about this. Is this a boxing issue?
The text was updated successfully, but these errors were encountered: