package com.shrimpking.t6;
/**
* Created by IntelliJ IDEA.
*
* @Author : Shrimpking
* @create 2024/10/1 14:45
*/
class Graph5<T> {
private T shape;
public T getShape()
{
return shape;
}
public void setShape(T shape)
{
this.shape = shape;
}
}
public class WildcardDemo8_6
{
//限定范围指定类及其子类
public void display(Graph5<? extends Number> graph){
System.out.println(graph.getShape());
}
public static void main(String[] args)
{
WildcardDemo8_6 wd = new WildcardDemo8_6();
Graph5<Integer> gaInt = new Graph5<>();
Graph5<Float> gaFloat = new Graph5<>();
gaInt.setShape(100);
gaFloat.setShape(101.1f);
wd.display(gaInt);
wd.display(gaFloat);
}
}
WildcardDemo8_6
最新推荐文章于 2025-01-16 19:10:13 发布
585

被折叠的 条评论
为什么被折叠?



