美文网首页
泛型-类

泛型-类

作者: 建康_木子 | 来源:发表于2019-06-28 16:45 被阅读0次
    泛型
    public class TTest <T>{
        private T c;
    
        public TTest(T c) {
            this.c = c;
        }
    
        public T getC() {
            return c;
        }
    
        public void setC(T c) {
            this.c = c;
        }
    
        public static void main(String[] args) {
            TTest<Dog> dog = new TTest<>(new Dog());
            dog.setC(new Dog("dog","black"));
            Dog c = dog.getC();
            System.out.println(c.getColor());
            System.out.println(c.getKind());
    
        }
    }
    

    相关文章

      网友评论

          本文标题:泛型-类

          本文链接:https://www.haomeiwen.com/subject/hhsecctx.html