第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何理解這種通用的netty代碼?

如何理解這種通用的netty代碼?

溫溫醬 2022-08-03 10:45:25
我是Java的新手,現(xiàn)在最近學(xué)習(xí)netty。一些通用的類代碼讓我感到困惑。像這樣:package io.netty.util;/** * A singleton which is safe to compare via the {@code ==} operator. Created and managed by {@link ConstantPool}. */public interface Constant<T extends Constant<T>> extends Comparable<T> {    /**     * Returns the unique number assigned to this {@link Constant}.     */    int id();    /**     * Returns the name of this {@link Constant}.     */    String name();}常量的通用定義是 self 的子類,這讓我感覺(jué)像一個(gè)循環(huán)引用。這種代碼的目的是什么?
查看完整描述

1 回答

?
智慧大石

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊

這個(gè)接口的設(shè)計(jì)師想要實(shí)際的實(shí)現(xiàn)實(shí)現(xiàn),因此是一段代碼。但不是比較任何對(duì)象,而是比較同一常量的其他實(shí)例。Comparableextends Comparable<T>


因此,在此上下文中表示實(shí)現(xiàn) 的實(shí)際類型。TConstant


如果你想實(shí)現(xiàn)它,你必須寫這樣的東西:


public class MyConstant implements Constant<MyConstant> {


    ...


    @Override

    public int compareTo(MyConstant myConstant) {

        return 0;

    }

}

上的約束強(qiáng)制實(shí)現(xiàn)提供方法。TcompareTo(MyConstant myConstant)


查看完整回答
反對(duì) 回復(fù) 2022-08-03
  • 1 回答
  • 0 關(guān)注
  • 137 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)