2

Sorry for the wordy title :) Here is the Scala object:

object TokenPosition extends java.lang.ThreadLocal[Int]

And here is the Java code that uses it:

TokenPosition$.MODULE$.set(position);

Eclipse gives me the following warning:

Type safety: The method set(Object) belongs to the raw type ThreadLocal. References to generic type ThreadLocal<T> should be parameterized

What should I do? Or is this an inherent limitation of Generics and Java/Scala interop?

3
  • does the simpler TokenPosition.set( position ) not work? does it still warn? Commented Mar 1, 2015 at 12:30
  • @SteveWaldman No, Java access to Scala object fields is a bit more complicated :) Commented Mar 1, 2015 at 12:43
  • i thought recent versions of Scala offered pretty forwarding methods, see "Forwarding Methods" twitter.github.io/scala_school/java.html here. But apparently that's only with companion objects, and probably not for inherited members. You could try adding a class TokenPosition; for the forwarding and specialize, object TokenPosition extends java.lang.ThreadLocal[Int] { def set( i : Int ) : Unit = super.set(i); } Commented Mar 1, 2015 at 13:31

1 Answer 1

1

Try changing Int to Integer, Int is like Java's int, and Integer is a wrapper, so it should help.

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

Comments

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.