⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex34.java

📁 thinking in java 经典书的习题答案 希望对大家有帮助啊
💻 JAVA
字号:
// generics/Ex34.java
// TIJ4 Chapter Generics, Exercise 34, page 709
/* Create a self-bounded generic type that contains an abstract method
* that takes an argument of the generic type parameter and produces a
* return value of the generic type parameter. In a non-abstract method
* of the class, call the abstract method and return its result. Inherit
* from the self-bounded type and test the resulting class.
*/

abstract class SelfBoundedType<T extends SelfBoundedType<T>> {
	abstract T f(T arg);
	T g(T arg) { 
		System.out.println("g(T arg)");
		return f(arg); 
	}	
}

class D extends SelfBoundedType<D> {
	D f(D arg) { 
		System.out.println("f(D arg)");
		return arg; 
	}	
}


public class Ex34 {
	public static void main(String[] args) {
		D d = new D();
		d.f(d).g(d);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -