Path: csiph.com!aioe.org!.POSTED.O5hsyUvK01te0L/SZurVSQ.user.gioia.aioe.org!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: Compare generics (that are numbers) Date: Wed, 29 Jul 2020 13:21:56 -0400 Organization: Aioe.org NNTP Server Lines: 32 Message-ID: References: <87k0ym73id.fsf@munus.decebal.nl> NNTP-Posting-Host: O5hsyUvK01te0L/SZurVSQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: csiph.com comp.lang.java.programmer:39590 On 7/29/2020 11:19 AM, Cecil Westerhof wrote: > I have a class that starts with: > abstract class CalcValuesGeneric { > > E will be Integer, int, Float or float. (For now, but always a Number.) > What is the best way to determine which of the two is lower? T extends Number? Example: public class NumFun { public static class Demo { public boolean gt(T a, T b) { return a.doubleValue() > b.doubleValue(); } } public static void main(String[] args) { Demo dd = new Demo<>(); System.out.println(dd.gt(1.0, 0.0)); System.out.println(dd.gt(1.0, 1.0)); System.out.println(dd.gt(0.0, 1.0)); Demo di = new Demo<>(); System.out.println(di.gt(1, 0)); System.out.println(di.gt(1, 1)); System.out.println(di.gt(0, 1)); } } Arne