萌新小白 定义泛型类问题 求大佬解答下!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Lin_bai_ 2020-10-13 11:35:12
定义泛型类(Miami<T>),在创造两个类(Detroit和Philadelphia)继承该泛型类,输出NBA中夺冠次数为3次的球队及年份,迈阿密热队(2006年、2012年、2013年)底特律活塞对(1989年、1990年、2004年),费城76人对(1955年、1967年、1983年)这个应该怎么写呀 求大佬解答下
...全文
733 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_39936465 2020-10-14
  • 打赏
  • 举报
回复
引用 13 楼 Lin_bai_ 的回复:
[quote=引用 11 楼 qq_39936465 的回复:][quote=引用 10 楼 Lin_bai_ 的回复:] 大佬 还可以仔细点吗 有些我没接触过
详细点是什么意思?[/quote] 就是注释[/quote] 没有很复杂的东西,你那句看不懂?
Lin_bai_ 2020-10-14
  • 打赏
  • 举报
回复
引用 11 楼 qq_39936465 的回复:
[quote=引用 10 楼 Lin_bai_ 的回复:] 大佬 还可以仔细点吗 有些我没接触过
详细点是什么意思?[/quote] 就是注释
Lin_bai_ 2020-10-14
  • 打赏
  • 举报
回复
就是注释
qq_39936465 2020-10-14
  • 打赏
  • 举报
回复
引用 10 楼 Lin_bai_ 的回复:
大佬 还可以仔细点吗 有些我没接触过
详细点是什么意思?
Lin_bai_ 2020-10-13
  • 打赏
  • 举报
回复
package GenericProgramma; //定义接口,接口中使用泛型 class Pair<K, V> { public K[] getKey; public V[] getValue; public Pair(K[] getKey,V[] getValue) { this.getKey = getKey; this.getValue = getValue; } public void showBookInfo() { System.out.println("银行名称\t\t存款时间\t户名\t币种\t存款金额\t账户余额"); System.out.println("----------------------------------------------"); for (int i = 0; i <getKey.length;i++) { System.out.print(getKey[i]+"\t"); } } public static void main(String[] args) { String[] info = {"张三","Rmb","8888.00RMB","18,888.88RMB"}; Pair<K, V><String> bank = new Pair<K, V><String>(info);//这句应该怎么写??? } }
Lin_bai_ 2020-10-13
  • 打赏
  • 举报
回复
引用 7 楼 qq_39936465 的回复:
[quote=引用 楼主 Lin_bai_ 的回复:]定义泛型类(Miami<T>),在创造两个类(Detroit和Philadelphia)继承该泛型类,输出NBA中夺冠次数为3次的球队及年份,迈阿密热队(2006年、2012年、2013年)底特律活塞对(1989年、1990年、2004年),费城76人对(1955年、1967年、1983年)这个应该怎么写呀 求大佬解答下

public class TestDeom {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Miami detroit=new Detroit("底特律活塞队(1989年、1990年、2004年)");
		Miami philadelphia=new Philadelphia("费城76队(1955年、1967年、1983年)");
		detroit.show();
		philadelphia.show();

	}

}

class Miami<T>{
	public T t;
	
	Miami(T t){
		this.t=t;
	}
	void show(){
		System.out.println(t);
	}
}

class Detroit extends Miami<String>{

	public Detroit(String t) {
		super(t);
		// TODO Auto-generated constructor stub
	}
	
}

class Philadelphia extends Miami<String>{

	public Philadelphia(String t) {
		super(t);
		// TODO Auto-generated constructor stub
	}
}
[/quote] 大佬 还可以仔细点吗 有些我没接触过
Lin_bai_ 2020-10-13
  • 打赏
  • 举报
回复
好的大佬谢谢
Lin_bai_ 2020-10-13
  • 打赏
  • 举报
回复
现在在学定义泛型类这个 所以碰到了
qq_39936465 2020-10-13
  • 打赏
  • 举报
回复
引用 楼主 Lin_bai_ 的回复:
定义泛型类(Miami<T>),在创造两个类(Detroit和Philadelphia)继承该泛型类,输出NBA中夺冠次数为3次的球队及年份,迈阿密热队(2006年、2012年、2013年)底特律活塞对(1989年、1990年、2004年),费城76人对(1955年、1967年、1983年)这个应该怎么写呀 求大佬解答下

public class TestDeom {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Miami detroit=new Detroit("底特律活塞队(1989年、1990年、2004年)");
		Miami philadelphia=new Philadelphia("费城76队(1955年、1967年、1983年)");
		detroit.show();
		philadelphia.show();

	}

}

class Miami<T>{
	public T t;
	
	Miami(T t){
		this.t=t;
	}
	void show(){
		System.out.println(t);
	}
}

class Detroit extends Miami<String>{

	public Detroit(String t) {
		super(t);
		// TODO Auto-generated constructor stub
	}
	
}

class Philadelphia extends Miami<String>{

	public Philadelphia(String t) {
		super(t);
		// TODO Auto-generated constructor stub
	}
}
KeepSayingNo 2020-10-13
  • 打赏
  • 举报
回复
泛型类(Miami<T>) 这个没看到你在哪里定义啊,而且你这个没必要定义泛型,你的年份、夺冠次数的类型不是明确的吗
qq_39936465 2020-10-13
  • 打赏
  • 举报
回复
引用 1 楼 Lin_bai_ 的回复:
package GenericProgramma; //定义接口,接口中使用泛型 class Pair<K, V> { public K[] getKey; public V[] getValue; public Pair(K[] getKey,V[] getValue) { this.getKey = getKey; this.getValue = getValue; } public void showBookInfo() { System.out.println("银行名称\t\t存款时间\t户名\t币种\t存款金额\t账户余额"); System.out.println("----------------------------------------------"); for (int i = 0; i <getKey.length;i++) { System.out.print(getKey[i]+"\t"); } } public static void main(String[] args) { String[] info = {"张三","Rmb","8888.00RMB","18,888.88RMB"}; Pair<K, V><String> bank = new Pair<K, V><String>(info);//这句应该怎么写??? } }

public  class Pair<K, V> {
	
	public K[] getKey;
	public V[] getValue;
	
	

	public Pair(K[] getKey, V[] getValue) {
		super();
		this.getKey = getKey;
		this.getValue = getValue;
	}
	
	public void showBookInfo() {
		System.out.println("银行名称\t\t存款时间\t户名\t币种\t存款金额\t账户余额");
        System.out.println("----------------------------------------------");
        for (int i = 0; i <getKey.length;i++)
        {
                System.out.print(getValue[i]+"\t");
        }
	}



	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Integer[] key= {1,2,3,4};
		String[] info= {"张三","Rmb","8888.00RMB","18,888.88RMB"};
		
		Pair<Integer, String> pair=new Pair<Integer, String>(key, info);
		
		pair.showBookInfo();

	}

}

Lin_bai_ 2020-10-13
  • 打赏
  • 举报
回复
最终成品 大佬看看还有什么地方可以优化的
Lin_bai_ 2020-10-13
  • 打赏
  • 举报
回复
package GenericProgramma; //定义接口,接口中使用泛型 class Pair<K, V> { private static Object Pair; public K[] getKey; public V[] getValue; public Pair() { } public Pair(K[] getKey,V[] getValue) { this.getKey = getKey; this.getValue = getValue; } public void showBookInfo() { System.out.println("银行名称\t\t存款时间\t户名\t币种\t存款金额\t账户余额"); System.out.println("----------------------------------------------"); for (int i = 0; i <getKey.length;i++) { System.out.print(getKey[i]+"\t"); } } public static void main(String[] args) { String[] info = {"张三","Rmb","8888.00RMB","18,888.88RMB"}; String[] info1 = {"张三","Rmb","8888.00RMB","18,888.88RMB"}; Pair <String,String> book = new Pair<String,String>(info,info1); book.showBookInfo(); } }

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧