V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
JohnZorn
V2EX  ›  Java

泛型

  •  
  •   JohnZorn · May 13, 2018 · 2984 views
    This topic created in 2911 days ago, the information mentioned may be changed or developed.

    Java 没办法通过传递 泛型的数组 来对这个数组进行复制并返回吧。。难受啊 写了半天 bug 最后通过反射使用 Array.newInstance(Class, int)写了一个可以拷贝,但是必须在运行时指定好 class 的具体类型,如果调用的使用也是一个 T.class 还是会凉。。问下各位大哥 java 有没有办法可以在这块绕过去啊。。

    4 replies    2018-05-14 12:32:34 +08:00
    fangchang
        1
    fangchang  
       May 13, 2018
    Collections.copy
    BBCCBB
        2
    BBCCBB  
       May 13, 2018
    Arrays.copy 了解一下?
    JohnZorn
        3
    JohnZorn  
    OP
       May 13, 2018
    。。哈哈尴尬了 我也刚看到 老哥们稳 像 jdk 低头
    HangoX
        4
    HangoX  
       May 14, 2018
    JAVA 的泛型只是编译时检查,运行中是不存在的,直接定义一个 object 就好了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1901 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 16:12 · PVG 00:12 · LAX 09:12 · JFK 12:12
    ♥ Do have faith in what you're doing.