0

a rather unusual behavior has occurred while I was using generics the other day. The compile could no longer determine properly the return type of a method inside a generic class that had a type argument.

I am basically having 4 classes:

AbstractModel, ConcreteModel, AbstractService< AbstractModel > and ConcreteService< Model >

In AbstractService I have a simple list of Longs and a method "getListOfLongs". Now something very very strange happens when I try to get my list of longs:

for(Long l : service.getListOfLongs()){

}enter image description here

And java compiler tells me my list is of Objects instead of longs.

You can try the example on my github: https://github.com/sashokbg/java-bug/

sashok_bg
  • 2,436
  • 1
  • 22
  • 33

0 Answers0