简体   繁体   English

实现接口时获取与超类相同的接口

[英]when implementing interfaces get same interface as superclass

in java i am using generics and in class i want to use implements interface(? extends class) and this interface is generic interface<T> but i get message as 在java中我使用generics ,在类中我想使用implements interface(? extends class) ,这个接口是generic interface<T>但是我得到的消息是

same interface as superclass

code example: 代码示例:

public interface ISomething<T>
{
    string Name { get; set; }
    string GetType(T t);
}

public class SomeClass implements ISomething<T extends SomeClass2>

is this possible? 这可能吗?

You cannot use a generic specifier that is not defined. 您不能使用未定义的通用说明符。 In your example for SomeClass , T is not declared. SomeClass的示例中,未声明T

This is invalid: 这是无效的:

public class SomeClass implements ISomething<T extends SomeClass2> 

Either of these are valid 这些都是有效的

public class SomeClass<T extends SomeClass2> implements ISomething<T>

or 要么

public class SomeClass implements ISomething<SomeClass2>  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从多个继承同一个超类的类实现回调接口时发生冲突 - Conflict when implementing callback interfaces from multiple classes that inherit from same superclass 当超类没有实现接口而是子类时,在接口子类和超类之间进行转换 - Casting between interface sublass and superclass when superclass is not implementing interface but subclass is 即使超类实现了相同的接口,在子类中实现接口是否有任何好处 - Is there any benefit in implementing a interface in a subclass even though the superclass implements the same interface 当子类和超类都实现相同的接口时发生了什么 - What happened when subclass and superclass both implement a same interface 用相同的方法在一个类中实现两个接口。 哪个接口方法被覆盖? - Implementing two interfaces in a class with same method. Which interface method is overridden? 使用greenDAO实现接口时出错 - Error when implementing interfaces with greenDAO 实现具有相同方法的多个接口 - Implementing multiple interfaces having same method 使用相同的方法签名实现多个接口 - Implementing multiple interfaces with same method signatures 实现两个都声明相同方法的接口时出现意外的编译器错误-(一个抽象,一个默认) - Unexpected compiler error when implementing 2 interfaces which both declare the same method - (one abstract and one default) 在实现java接口时,确保“Object o”参数具有相同的泛型类型 - Ensuring that “Object o” parameter is of the same generic type when implementing java interfaces
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM