java泛型问题代码如下:
importjava.util.ArrayList;importjava.util.List;publicclassFTestDraw{publicstaticvoidm...
import java.util.ArrayList;
import java.util.List;
public class FTestDraw {
public static void main(String[] args) {
}
}
abstract class Shape{
abstract void draw();
}
class Circle extends Shape{
@Override
void draw() {
System.out.println("这是 圆形");
}
}
class Rectangle extends Shape{
void draw(){
System.out.println("这是长方形");
}
}
class Triangle extends Shape{
void draw(){
System.out.println("这是三角形");
}
}
class DrawMethod<T>{
public DrawMethod(T<? extends Shape> tt){
}
}
就是想构造方法DrawMethod里的对象都是Shape的子类对象 展开
import java.util.List;
public class FTestDraw {
public static void main(String[] args) {
}
}
abstract class Shape{
abstract void draw();
}
class Circle extends Shape{
@Override
void draw() {
System.out.println("这是 圆形");
}
}
class Rectangle extends Shape{
void draw(){
System.out.println("这是长方形");
}
}
class Triangle extends Shape{
void draw(){
System.out.println("这是三角形");
}
}
class DrawMethod<T>{
public DrawMethod(T<? extends Shape> tt){
}
}
就是想构造方法DrawMethod里的对象都是Shape的子类对象 展开
2个回答
展开全部
//是这样吗?
public class FTestDraw {
public static void main(String[] args) {
DrawMethod<Shape> dm = new DrawMethod<Shape>(new Circle());
dm.shape.draw();
}
}
abstract class Shape{
abstract void draw();
}
class Circle extends Shape{
@Override
void draw() {
System.out.println("这是圆形");
}
}
class Rectangle extends Shape{
@Override
void draw(){
System.out.println("这是长方形");
}
}
class Triangle extends Shape{
@Override
void draw(){
System.out.println("这是三角形");
}
}
class DrawMethod<T extends Shape>{
T shape = null;
public DrawMethod(T tt){
shape = tt;
}
}
public class FTestDraw {
public static void main(String[] args) {
DrawMethod<Shape> dm = new DrawMethod<Shape>(new Circle());
dm.shape.draw();
}
}
abstract class Shape{
abstract void draw();
}
class Circle extends Shape{
@Override
void draw() {
System.out.println("这是圆形");
}
}
class Rectangle extends Shape{
@Override
void draw(){
System.out.println("这是长方形");
}
}
class Triangle extends Shape{
@Override
void draw(){
System.out.println("这是三角形");
}
}
class DrawMethod<T extends Shape>{
T shape = null;
public DrawMethod(T tt){
shape = tt;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询