How to use a method reference on a static import?

Viewed 2428

When using map functions in java I can do the following:

import com.example.MyClass;

someStream.map(MyClass::myStaticMethod)

but in my project we sometimes use static imports, how can I reference the myStaticMethod when the import is static?

I would think this would work but it doesn't:

import static com.example.MyClass.myStaticMethod;

someStream.map(myStaticMethod); //does not compile

Why does this not work? Am I 'stuck' with using the first example or are there other solutions.

4 Answers
Related