aspose file tools*
The moose likes Beginning Java and the fly likes I can NOT compile first class below Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I can NOT compile first class below " Watch "I can NOT compile first class below " New topic
Author

I can NOT compile first class below

Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 402
I can NOT compile first class below I get the>>>.
//Chapter: 18-Generics, Problem - textbook:HTP7 JAVA DEITEL (c)2007, Exe.:18.4

C:\Users\User\Documents\TextBooksDataFiles\RexPractice\JAVA\MySolutions\18-4>javac SelectionSort.java
SelectionSort.java:53: incompatible types
found : T
required: T
T x = data[smallest];
^
SelectionSort.java:54: incompatible types
found : T
required: T
T y = data[index];
^
2 errors

Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
I changed your code to compile. I did not test it. I also don't know whether it will do what you intended it to do. In answer to your original queston, you were defining T at the class level and T at the method level so you had two Ts defined. In your original code, try changing the method T to, for example S and and the compiler error will not be so confusing. BTW, You cannot use primitive types with generics.

Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 402
exe instr: given an example in another chapter in selection sort[Searching/Sorting chapter], problem was use method sort with <T extends Comparable<T>>, and NOT class with this, to sort 10 numbers (in the original problem numbers in array random generated), well?

you say "try changing the method T to, for example S and and the compiler error will not be so confusing" how then bind T to S?
may wrtite this without in class the T but only in method: public < T extends Comparable< T >> void sort(T[] data) ???

BTW your code compiles and run correct.

To appear the contents of an obj array like Integer or Float I must use absolutelly: ENHANCED FOR LOOP correct?
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 402
My code It compile/run success with below (is any error)?
can you comment on it (see and prior post)...

Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Leonidas Savvides wrote:you say "try changing the method T to, for example S and and the compiler error will not be so confusing" how then bind T to S?
You cannot. T and S are different class types. I only suggested that to clear up confusion about the compiler error - not to remove the compiler error.

Leonidas Savvides wrote:To appear the contents of an obj array like Integer or Float I must use absolutelly: ENHANCED FOR LOOP correct?
No. See this recent post: http://www.coderanch.com/t/500383/java/java/operator-works-Integer-class
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 402
well since My code It compile/run success with below (is any error/improvement)?
can you comment on it (see code in prior post)...
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Leonidas Savvides wrote:well since My code It compile/run success with below (is any error/improvement)?
can you comment on it (see code in prior post)...
I think they just wanted to show that you have choices in code design.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I can NOT compile first class below
 
Similar Threads
static final int[] wont print unsorted column
Sorting Arrays
Two dimensional array total and sort
question on array and printing
Large arrays