0

I have a piece of code under "test" package as below

object TestTraitsUnderObject {

  trait InnerOperation[T] {

  }

  def main(args: Array[String]): Unit = {
    Class.forName("test.OuterOperation")
    Class.forName("test.TestTraitsUnderObject.InnerOperation")

  }
}

trait OuterOperation[T] {

}

seems I can load the class for Outer trait correctly , but for nested trait, the classpath is incorrect ? why is that ? How I can load the `nested trait class correctly ?

Thanks

1 Answer 1

1

Use $

Class.forName("test.TestTraitsUnderObject$InnerOperation")

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, Another question ,how to load class for nested class in a package object ?
"test.package$Inner" if you have Inner in test package object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.