Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Java generics question
New Posts  All Forums:Forum Nav:

Java generics question

post #1 of 8
Thread Starter 
What is the difference between these two class declarations?

public class MyList

and ---

public class MyList>
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
post #2 of 8
Can you post some more of you're code, I can't see what you are doing here... Are you trying to make a list of a certain type List or extend a list i.e.. MyArrayList?
^3
(11 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i7 5930K  EVGA x99 Micro EVGA GTX 980 SC ACX 16GB Corsair DDR4 Vengeance LPX Black PC4-21300 
Hard DriveCoolingOSMonitor
500GB Samsung 840 EVO H105 Win 10 ASUS ROG PG279 
KeyboardPowerCase
Ducky Shine 1 MX-Red Corsair AX 860i  Fractal Design Node 804 Black 
CPUGraphicsRAMHard Drive
Core i7 @ 2.6  GT650 16GB of 1600 MHz DDR3L SDRAM 256GB SSD 
OSMonitorKeyboard
Mac OSX Lion Retina Display US layout 
  hide details  
Reply
^3
(11 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i7 5930K  EVGA x99 Micro EVGA GTX 980 SC ACX 16GB Corsair DDR4 Vengeance LPX Black PC4-21300 
Hard DriveCoolingOSMonitor
500GB Samsung 840 EVO H105 Win 10 ASUS ROG PG279 
KeyboardPowerCase
Ducky Shine 1 MX-Red Corsair AX 860i  Fractal Design Node 804 Black 
CPUGraphicsRAMHard Drive
Core i7 @ 2.6  GT650 16GB of 1600 MHz DDR3L SDRAM 256GB SSD 
OSMonitorKeyboard
Mac OSX Lion Retina Display US layout 
  hide details  
Reply
post #3 of 8
Thread Starter 
Trying to make a linked list, but using a comparator with it is giving me problems. What's a good site to post code to?
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
post #4 of 8
Can you post your code here? Is MyList a custom LinkedList class that you made? All you have to do to sort using the comparator interface is create a list of objects that implement the comparator interface and make a call to Collections.sort(List list);
baby cakes
(13 items)
 
Macbook 4,1
(13 items)
 
 
CPUMotherboardGraphicsRAM
i7 930 [4.01Ghz vCore 1.28125 HT on] GA-X58A-UD3R ZOTAC GTX 460 1GB SLI [840/1680/1900 @stock volts] CORSAIR XMS3 6GB (3 x 2GB) 1600Mhz 
Hard DriveOptical DriveOSMonitor
C300 64GB SATA III, 2x F3 1TB 7200rpm RAID 0 Sony Optiarc 24X DVD/CD Ubuntu 14.04 22" Dell SP2009W 1680x1050 
PowerCase
CORSAIR HX 750W Cooler Master HAF 922 
CPUMotherboardGraphicsRAM
Core 2 Duo 2.4Ghz Penryn T8300 Some logical board GMA X3100 4GB (2x2GB) DDR2 667Mhz 
Hard DriveOptical DriveOSMonitor
Hitachi 160 GB 5400 RPM SATA II Combo drive OSX 10.6.4 (Snow leopard) 13.3" 1280x800 TFT 
PowerCase
Dying battery White macbook case 
  hide details  
Reply
baby cakes
(13 items)
 
Macbook 4,1
(13 items)
 
 
CPUMotherboardGraphicsRAM
i7 930 [4.01Ghz vCore 1.28125 HT on] GA-X58A-UD3R ZOTAC GTX 460 1GB SLI [840/1680/1900 @stock volts] CORSAIR XMS3 6GB (3 x 2GB) 1600Mhz 
Hard DriveOptical DriveOSMonitor
C300 64GB SATA III, 2x F3 1TB 7200rpm RAID 0 Sony Optiarc 24X DVD/CD Ubuntu 14.04 22" Dell SP2009W 1680x1050 
PowerCase
CORSAIR HX 750W Cooler Master HAF 922 
CPUMotherboardGraphicsRAM
Core 2 Duo 2.4Ghz Penryn T8300 Some logical board GMA X3100 4GB (2x2GB) DDR2 667Mhz 
Hard DriveOptical DriveOSMonitor
Hitachi 160 GB 5400 RPM SATA II Combo drive OSX 10.6.4 (Snow leopard) 13.3" 1280x800 TFT 
PowerCase
Dying battery White macbook case 
  hide details  
Reply
post #5 of 8
Thread Starter 
Unfortunately I can't make a call to collections sort. I have to build the nodes and the sorting algorithm myself.

http://pastebin.com/BeSyjsyH

Anyways, I can't seem to display my question on this site so I put it up on pastebin. I'm a little lost on generics.
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
post #6 of 8
Comparable is an interface so you have to implement it. You do this by using:

Myclass implements Comparable {
}

Unless you're trying to create "sub-interfaces" that pretty much extend the functionality of the Comparable interface, you should always be doing it that way.

Since Comparable takes objects, you can create your own generic class (such as a container that takes integers in this case) so it's easier to work with (which is probably what you're doing now). Then implement the Comparable method inside your class.
Mr Jiggawatts
(13 items)
 
  
CPUMotherboardGraphicsRAM
1090T@4GHz@1.46V Ultra LLC/3GHz CPU-NB@1.33V Asus Crosshair V Formula MSI GTX560-TI 1GB TF II Patriot Viper Xtreme 1600 8GB (2x4GB) 8-9-8-24 
Hard DriveOSMonitorKeyboard
Intel X25-V 40GB, Kingston SSDNow 64GB Windows 7 Ultimate LG Flatron W2353V Razer Arctosa 
PowerCaseMouse
Antec HCG-900W Antec Lanboy Air Yellow Razer Abbysus 
  hide details  
Reply
Mr Jiggawatts
(13 items)
 
  
CPUMotherboardGraphicsRAM
1090T@4GHz@1.46V Ultra LLC/3GHz CPU-NB@1.33V Asus Crosshair V Formula MSI GTX560-TI 1GB TF II Patriot Viper Xtreme 1600 8GB (2x4GB) 8-9-8-24 
Hard DriveOSMonitorKeyboard
Intel X25-V 40GB, Kingston SSDNow 64GB Windows 7 Ultimate LG Flatron W2353V Razer Arctosa 
PowerCaseMouse
Antec HCG-900W Antec Lanboy Air Yellow Razer Abbysus 
  hide details  
Reply
post #7 of 8
Thread Starter 
Thanks. The problem was that I was trying to implement the comparable interface inside of my orderedList class instead of my Node subclass.

When I create and orderedList inside of my test class, is it proper to declare the type of variable that the generic OrderedList class is expected to use?

For example:

http://pastebin.com/9GhGgwzi
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
post #8 of 8
Yes, that is how you woud declare an OrderList that contains Integer objects.
baby cakes
(13 items)
 
Macbook 4,1
(13 items)
 
 
CPUMotherboardGraphicsRAM
i7 930 [4.01Ghz vCore 1.28125 HT on] GA-X58A-UD3R ZOTAC GTX 460 1GB SLI [840/1680/1900 @stock volts] CORSAIR XMS3 6GB (3 x 2GB) 1600Mhz 
Hard DriveOptical DriveOSMonitor
C300 64GB SATA III, 2x F3 1TB 7200rpm RAID 0 Sony Optiarc 24X DVD/CD Ubuntu 14.04 22" Dell SP2009W 1680x1050 
PowerCase
CORSAIR HX 750W Cooler Master HAF 922 
CPUMotherboardGraphicsRAM
Core 2 Duo 2.4Ghz Penryn T8300 Some logical board GMA X3100 4GB (2x2GB) DDR2 667Mhz 
Hard DriveOptical DriveOSMonitor
Hitachi 160 GB 5400 RPM SATA II Combo drive OSX 10.6.4 (Snow leopard) 13.3" 1280x800 TFT 
PowerCase
Dying battery White macbook case 
  hide details  
Reply
baby cakes
(13 items)
 
Macbook 4,1
(13 items)
 
 
CPUMotherboardGraphicsRAM
i7 930 [4.01Ghz vCore 1.28125 HT on] GA-X58A-UD3R ZOTAC GTX 460 1GB SLI [840/1680/1900 @stock volts] CORSAIR XMS3 6GB (3 x 2GB) 1600Mhz 
Hard DriveOptical DriveOSMonitor
C300 64GB SATA III, 2x F3 1TB 7200rpm RAID 0 Sony Optiarc 24X DVD/CD Ubuntu 14.04 22" Dell SP2009W 1680x1050 
PowerCase
CORSAIR HX 750W Cooler Master HAF 922 
CPUMotherboardGraphicsRAM
Core 2 Duo 2.4Ghz Penryn T8300 Some logical board GMA X3100 4GB (2x2GB) DDR2 667Mhz 
Hard DriveOptical DriveOSMonitor
Hitachi 160 GB 5400 RPM SATA II Combo drive OSX 10.6.4 (Snow leopard) 13.3" 1280x800 TFT 
PowerCase
Dying battery White macbook case 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Java generics question