Method with generics in inherited type [closed]

1

How do I use two types in the generics method, to sum only the areas of the Quadrado and Retangulo classes.

I tried a method like this:

public static double soma(Forma <? extends Quadrado> elementos) {


        return elementos.getArea();

    }

and Forma and abstract .

    
asked by anonymous 25.11.2016 / 02:27

1 answer

1

This is not possible in Java.

Quadrado and Retangulo inherit from Forma ? Or does one inherit from the other? Well, if it is, is a classic error . But let's consider the first one.

public static <T extends Forma> double soma(T elementos) {
    return elementos.getArea();
}

What you should do within the method I do not know since there is no information on this.

    
25.11.2016 / 10:27