V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yanzixuan
V2EX  ›  Java

求问这个泛型是啥意思?

  •  
  •   yanzixuan · 2019-03-11 16:50:06 +08:00 · 1820 次点击
    这是一个创建于 1844 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在学习 netty,但是某些泛型的高级用法没人教的话感觉看不懂。比如这样的

    package io.netty.util;
    
    /**
     * Holds {@link Attribute}s which can be accessed via {@link AttributeKey}.
     *
     * Implementations must be Thread-safe.
     */
    public interface AttributeMap {
        /**
         * Get the {@link Attribute} for the given {@link AttributeKey}. This method will never return null, but may return
         * an {@link Attribute} which does not have a value set yet.
         */
        <T> Attribute<T> attr(AttributeKey<T> key);
    
        /**
         * Returns {@code} true if and only if the given {@link Attribute} exists in this {@link AttributeMap}.
         */
        <T> boolean hasAttr(AttributeKey<T> key);
    }
    

    在 boolen 之前的<T>是啥意思,有达人知道么?

    求教

    dallaslu
        1
    dallaslu  
       2019-03-11 17:00:19 +08:00   ❤️ 1
    就是范型的声明啊,在方法的返回值前声明的,意思是这是一个范型方法。
    leonard916
        2
    leonard916  
       2019-03-11 19:29:15 +08:00
    声明后面的泛型
    xueyingbing
        3
    xueyingbing  
       2019-03-11 21:48:33 +08:00
    泛型方法,建议系统性看一下泛型,就会了解了。
    如果不了解的话,也可以暂时忽略,不影响。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4131 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:16 · PVG 18:16 · LAX 03:16 · JFK 06:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.