I have a project that is mixed Java/Scala, it is Java GUI code that makes use of a Scala library. Is there a way to write Scala code such that it will emit Java enums on compile time? The approaches I tried so far (sealed case classes, extend Enumeration) seem to generate normal classes which makes working with them from Java much hairier than straight up enums.
views:
567answers:
2
A:
Scala only supports Java 1.4 features at this point.
Java Enums were introduced in Java 1.5.
drudru
2009-07-07 04:06:45
Er, apart from generics
oxbow_lakes
2009-07-07 07:20:55
Generics are implemented with type erasure, after compilation there are no generics anymore. But Scala supports annotations and those are retained when compiling to bytecode and that is most definitely a Java 1.5 feature.
Boris Terzic
2009-07-07 07:47:53
Generics in java is implemented via type erasure as well
oxbow_lakes
2009-07-07 09:28:05
What Boris meant is that Scala only support JVM 1.4 features. Language features that do no exist on the bytecode are irrelevant. Except, of course, interface-wise. :-)
Daniel
2009-07-07 13:21:43
@Daniel, My understanding is that JVM bytecode hasn't changed since 1.0. So the only differences between 1.4 and 1.5 are language features.
Jay Conrod
2009-07-07 15:27:47
The class file format was extended to accommodate at least enums and annotations, but it's possible they managed it in a backwards compatible way. JSR 202 should have the details ( http://www.jcp.org/en/jsr/detail?id=202 )
Boris Terzic
2009-07-07 20:17:54
+3
A:
Why can't you write your enum
class in Java? Mixed-source (i.e. Java + Scala) projects are perfectly feasible...
oxbow_lakes
2009-07-07 07:21:44
Indeed, that was also my conclusion, I will accept this answer. Maven support for mixed projects is still very flaky though.
Boris Terzic
2009-07-07 07:42:50