1

I have a java maven project which has dependency to scala project. I try to implement scala trait in java. The trait is store in packge object, when I try to implement it project fallen with compile time error Here sources:

scala source:

package com.compile.error

package object dummies {
    trait BaseDummy {
        def name: String
    }
    trait ChildDummy extends BaseDummy{

    }
}

java source:

//Uncoment for compile error
public class WhantImplementScalaTrait  /*implements com.compile.error.dummies.package$ChildDummy*/ {
}

So how implement scala trait as java interface if it in package object?

Full sources you can download here.

UPDATED

The command

javap package$ChildDummy.class

Gets result:

public interface com.compile.error.dummies.package$ChildDummy extends com.compile.error.dummies.package$BaseDummy {
}    

Tried imports

  • com.compile.error.dummies.package$.ChildDummy$Class
  • com.compile.error.dummies.package$.ChildDummy
  • com.compile.error.dummies.package$.MODULE$.ChildDummy$Class
  • com.compile.error.dummies.package$.MODULE$.ChildDummy
  • com.compile.error.dummies.package$ChildDummy
  • com.compile.error.dummies.package$ChildDummy$Class
Cherry
  • 31,309
  • 66
  • 224
  • 364
  • Similar question [here](http://stackoverflow.com/questions/9436074/scala-trait-companion-object-is-not-visible-in-java) but it about *methods* **not** about interfaces. – Cherry Aug 07 '14 at 04:13
  • You could try using reflection list all the classes in that package, maybe: http://stackoverflow.com/questions/520328/can-you-find-all-classes-in-a-package-using-reflection – mdenton8 Aug 07 '14 at 07:40
  • possible duplicate of [Using Scala class defined in package object from Java](http://stackoverflow.com/questions/23170058/using-scala-class-defined-in-package-object-from-java) – Cherry Aug 08 '14 at 05:49

0 Answers0