解决方法类型参数下限的方法

时间:2020-03-30 14:14:48

标签: java generics type-bounds

我想要一个带有实例方法### importing libraries ### from tkinter import * ### creating tk and the principal frame ### tk = Tk() tk.title("calculator") f1 = Frame(tk,bg="blue",height=1200, width=1200) f1.pack() ### creating and showing the buttons ### bruh = Button(f1,background="white", text="moltiplica") bruh.pack(padx=30,pady=1) ### running the whole thing ### tk.mainloop() 的泛型类db_info = cursor.execute("SELECT * FROM usersTable"); if login_user in db_info: game() else: messagebox.showerror("Invalid Details", "Inputted details are invalid!") ,该方法带有另一个Foo<T>对象operation,并返回一个新的Foo对象其类型参数concretion是other的{​​{1}}和Foo的{​​{1}}的超类型。

就是这样,

this

如果允许的话。

现在,我知道类型参数aren't allowed的下限,并且我知道其背后的一般原理。但是在这种特殊情况下,它们将很有用。 (Ergo,请注意,我并不是在要求whether,或者他们why是不允许的。),我在寻找解决方法。

here列出的两个解决方法均无效,因为我需要确切的返回类型T(我无法将其擦除为other),也无法将其转换为{静态方法,因为该方法是抽象的(它是多态的)。


为了更好地说明这一点的有效性,下面是一个更具体的示例:

T

等效的静态方法为:

public abstract class Foo<T> {
    public abstract <U super T> Foo<U> operation(Foo<? extends U> other);
}

0 个答案:

没有答案
相关问题