求问这个泛型是啥意思?

2019-03-11 16:50:06 +08:00
 yanzixuan

最近在学习 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>是啥意思,有达人知道么?

求教

1853 次点击
所在节点    Java
3 条回复
dallaslu
2019-03-11 17:00:19 +08:00
就是范型的声明啊,在方法的返回值前声明的,意思是这是一个范型方法。
leonard916
2019-03-11 19:29:15 +08:00
声明后面的泛型
xueyingbing
2019-03-11 21:48:33 +08:00
泛型方法,建议系统性看一下泛型,就会了解了。
如果不了解的话,也可以暂时忽略,不影响。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/543390

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX