看待一段代码,一个类的定义,其中&BaseEnum>extendsBaseTypeHandler
2 回答
吃鸡游戏
TA贡献1829条经验 获得超7个赞
packageTypeVarMembers;classC{publicvoidmCPublic(){}protectedvoidmCProtected(){}voidmCPackage(){}privatevoidmCPrivate(){}}interfaceI{voidmI();}classCTextendsCimplementsI{publicvoidmI(){}}classTest{voidtest(Tt){ t.mI();//OKt.mCPublic();//OKt.mCProtected();//OKt.mCPackage();//OKt.mCPrivate();//Compile-timeerror}}ThetypevariableThasthesamemembersastheintersectiontypeC&I,whichinturnhasthesamemembersastheemptyclassCT,definedinthesamescopewithequivalentsupertypes.Themembersofaninterfacearealwayspublic,andthereforealwaysinherited`(unlessoverridden).HencemIisamemberofCTandofT.AmongthemembersofC,allbutmCPrivateareinheritedbyCT,andarethereforemembersofbothCTandT.IfChadbeendeclaredinadifferentpackagethanT,thenthecalltomCPackagewouldgiverisetoacompile-timeerror,asthatmemberwouldnotbeaccessibleatthepointwhereTisdeclared.来自TheJava®LanguageSpecification,JavaSE8Edition$4.4TypeVariablesP58~59
守着星空守着你
TA贡献1799条经验 获得超8个赞
1楼正解&在java中是and的意思,在泛型的应用场景,含义基本不变。publicclassEnumTypeHandler&BaseEnum>extendsBaseTypeHandler 中的EextendsEnum>&BaseEnum可以理解为Eextends(Enum>&BaseEnum),结合extends的含义,及E为Enum>和BaseEnum的子类
添加回答
举报
0/150
提交
取消