Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does Scala store information that cannot be represented in Java?

Tags:

bytecode

scala

There are some constructs that don't have equivalents in java. Examples would be

  • named parameters
  • instance private members

Where/How does Scala store the information necessary for this stuff (some kind of flag in the first case, the parameter names in the second case?

If I get it right this has to get stored in the byte code, since it works even if I just have a compiled library without the source code!?

like image 849
Jens Schauder Avatar asked May 09 '13 07:05

Jens Schauder


People also ask

Is everything in Scala an object?

Not everything is an object in Scala, though more things are objects in Scala than their analogues in Java. The advantage of objects is that they're bags of state which also have some behavior coupled with them. With the addition of polymorphism, objects give you ways of changing the implicit behavior and state.

Can Scala run Java code?

Is it possible to mix Scala and Java code? Yes, there is the ability to mix both types of code. It is possible to create an SBT project, put Scala code in src/main/scala and java code in src/main/java in the same project and make it work.


1 Answers

This information is captured in an annotation named ScalaSig in the class file (see this answer for an example).

You can view the (not very human-friendly) annotation with javap -verbose, or parse it using an internal API, but in general neither should be necessary.

like image 155
Travis Brown Avatar answered Sep 28 '22 09:09

Travis Brown