• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generic Static method with a "method undefined" Error

 
Greenhorn
Posts: 16
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day everyone,

The requirement is: Storing int type elements in a List, then writing a Helper class with two static methods to sort those int type elements in the List in increasing and decreasing order.

I passed the reference variable "list" to the method increasingSort(line 23), then I got an error: "The method toArray(Integer[]) is undefined for the type List", when I was trying to use the toArray() method(line 31).

I know toArray() method belongs to List, this error is really confused...

Can anyone explain this to me...Thanks a lot!

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hint: Is there a difference between this ...

Xiaolong Bao wrote:



and this ??



Henry
 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
toArray method requires its argument to be of type the same as Generic type of List itself. So introduce generic type for argument List list like:
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:Hint: Is there a difference between this ...and this ??


Or indeed:Note - no 'static'.

My main worry about your method is that it doesn't actually sort. It simply display the contents of a (presumably) sorted List.

Naming is very important.

Winston
 
Xiaolong Bao
Greenhorn
Posts: 16
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Henry Wong wrote:Hint: Is there a difference between this ...and this ??


Or indeed:Note - no 'static'.

My main worry about your method is that it doesn't actually sort. It simply display the contents of a (presumably) sorted List.

Naming is very important.

Winston



Actually it's just a part of the code and hasn't been finished yet....Thanks for your reply!
 
Xiaolong Bao
Greenhorn
Posts: 16
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Volodymyr Levytskyi wrote:toArray method requires its argument to be of type the same as Generic type of List itself. So introduce generic type for argument List list like:



Really appreciating your answer, it's the right solution and I've know what my mistake is....
 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic