“generic method” “absolute value” java
问题 I want to make a stupid example for my students, but a don´t know if I can do what I´m thinking I want to do the abs method with generics. My idea is something similar to this: public class MiMath { public static <T extends Number> T abs(T objeto) { if (objeto.doubleValue()<0) return (T) -objeto.doubleValue(); else return objeto; } } in this linea return (T) -objeto.doubleValue(); eclipse says that (T) is not a Type 回答1: The problem is that what you are doing here with the (T) is not really a