Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > 1.5.0 Syntex Question

Reply
Thread Tools

1.5.0 Syntex Question

 
 
Aryeh M. Friedman
Guest
Posts: n/a
 
      03-17-2005
I am new to 1.5.0 and was wondering if anyone knows how to fix the following
syntex/semantic errors. The following code produces the following error
(javac Debug.java Assert.java -xlint):

public class Assert {

 
Reply With Quote
 
 
 
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      03-17-2005
"Aryeh M. Friedman" <> writes:

> Assert.java:81: warning: [unchecked] unchecked cast
> found : java.lang.Object
> required: java.lang.Comparable<java.lang.Object>
> if(((Comparable<Object>) val).compareTo(min)<=0)


You can turn off the cast check warning using a variant on the -lint
command line option to javac.

> TestFailException.java:11: warning: [serial] serializable class
> unittest.TestFailException has no definition of serialVersionUID
> public class TestFailException extends RuntimeException
> ^


The same with that warning.

> TestResult.java:49: unittest.TestErrorException is abstract; cannot be
> instantiated
> throw new TestErrorException();
> ^


You need to make a non-abstract subclass.

> TestResultTest.java:57: incompatible types
> found : unittest.TestErrorException
> required: java.lang.Throwable
> } catch(TestErrorException e) {
> ^


Your TestErrorException needs to extend Throwable or one of its
subclasses. Unlike C++, you cannot throw any object you want.

> Assert.assertRange(5,0,9);
> ^


When autoboxing the 5, the compiler uses Integer: That class does not
implement Comparable<Object> but Comparable<Integer> which is not the
same thing.

> AssertTest.java:89:
> assertRange(java.lang.Comparable<java.lang.Object> ,java.lang.Object,java.lang.Object)
> in unittest.Assert cannot be applied to (int,int,int)
> Assert.assertRange(-1,0,9);
> ^


Same thing.

> AssertTest.java:90:
> assertRange(java.lang.Comparable<java.lang.Object> ,java.lang.Object,java.lang.Object)
> in unittest.Assert cannot be applied to (int,int,int)
> Assert.assertRange(10,0,9);
> ^


And again.

The rest are the same you got before.
 
Reply With Quote
 
 
 
 
Alan Moore
Guest
Posts: n/a
 
      03-17-2005
On Thu, 17 Mar 2005 01:57:23 -0500, "Aryeh M. Friedman"
<> wrote:

>public class Assert {
>
> .
> .
> .
>
> /**
>
> if val is between (inclusive) min and max pass else fail
>
> @param val the "real" value
> @param min the minimal value allowed
> @param max the maximum value allowed
> */
>
> public static void assertRange(Object val,Object min,Object max)
> {
> try {
> if(((Comparable<Object>) val).compareTo(min)<0)
> _assert("assertRange: value to low minimum value is "
> + min + " got " + val);
>
> // repeat test to see if more then max
> } catch(ClassCastException e) {
> TestResult.error(e);
> }
> }
>}


Change the method signature to:

public static <T extends Comparable<T>> void
assertRange(T val, T min, T max)


Then you won't need to do any casts, and the "unchecked" warnings
should go away.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SYNTEX ERROR in C# ghufran Software 0 07-28-2008 01:54 PM
Strange syntex: beginner Nagrik Perl Misc 5 03-21-2008 03:47 AM
Help with error 500, but compiles and runs on my server and syntex checks out froil Perl Misc 4 03-08-2006 02:47 AM
client script syntex error Nikhil Patel ASP .Net 1 10-07-2004 03:39 PM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57