Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 4
    That's more of a copy than a cast, though. Commented Feb 15, 2016 at 11:15
  • The casting mentioned in the accepted anser didn't work for me. Also I was on Java 7. But Guava's FluentIterable worked for me. Commented Nov 2, 2017 at 23:05
  • This is what I was looking for, I just didn't know the syntax Commented Mar 28, 2018 at 17:57
  • This is not working for me. I get error java.lang.ClassCastException: class java.lang.Object cannot cast to class my.package.MyInterface. java.lang.Object is in module java.base of loader bootstrap; my.package.MyInterface is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.restartClassLoader Commented Oct 17, 2021 at 21:57