简体   繁体   中英

Possible loss of precision and symbol errors in Java

This is the line of code I'm trying to make work:

 if (rend > num) rend = num; 

But Dr.Java spits out this error:

File: /Users/spencer/Downloads/MergeTDNonrecursive.java  [line: 75]
Error: /Users/spencer/Downloads/MergeTDNonrecursive.java:75: possible loss of precision
found   : long
required: int

Similarly,

sort(a, aux, 0, a.length-1);

is prompting the error:

    File: /Users/spencer/Downloads/MergeTDNonrecursive.java  [line: 106]
Error: /Users/spencer/Downloads/MergeTDNonrecursive.java:106: cannot find symbol
symbol  : method sort(java.lang.Comparable[],java.lang.Comparable[],int,int)
location: class MergeTDNonrecursive

I've searched hi and lo (lol), but in all seriousness I can't see what's going wrong with my code.

EDIT: I should mention that I don't know the difference between long and int, specifically because I don't know what long is. How can I remedy this in my code? And no, these errors are popping up when I try to compile.

The error message is quite specific: You're apparently trying to assign a variable with a larger range ( long ) to one with a smaller range ( int ), and Java requires you to specifically okay the restriction with a cast.

If you have

int rend;
long num;

there's a chance that the value in num is too big to fit in rend . You can tell Java that it's okay to possibly lose information by saying this:

rend = (int) num;

However, this is usually a logical error, and you should address why the two variables are of differing sizes.

The cannot find symbol isn't "similar", it's a completely different error, and it's because you're calling sort , but no sort method exists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM