Simple Java generics question -


I have a way to calculate the meaning of an integer, double and float type linked list.

The problem is sum + = i statement, because Java says that the operator is not defined for the type of object.

I can make an artist, but if the linkedist was a type of float, for example, and the cast was in integer, I was not calculating the correct meaning.

What should I do? Thank you.

  Public double meaning (linked list & lt ?? & gt; l) {double sum = 0; Int n = 0; For (object i: L) {n ++; Zodiac + = i; } Refund amount / N; }  

You should restrict your list to S. This is a general superclass for integer , float , double and other numerical types, it has no operators defined, only for conversion methods. Double , but it is enough for you:

  Public double meaning (linked list & lt;; number & gt; l) {double sum = 0; Int n = 0; For (number i: l) {n ++; Yoga = = i.doubleValue (); } Refund amount / N; }  

Comments