How can I cast a list using generics in Java?

前端 未结 5 1553
刺人心
刺人心 2021-02-02 09:20

Please consider the following snippet:

public interface MyInterface {

    public int getId();
}

public class MyPojo implements MyInterface {

    private int i         


        
5条回答
  •  感情败类
    2021-02-02 10:14

    Choosing the right type from the start is best, however to answer your question you can use type erasure.

    return (ArrayList) (ArrayList) myPojos;

提交回复
热议问题