• 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

@Override toString(double[] a)

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Mooses,
I'm trying to override toString(double[] a) method, to get my own way of printing Arrays.toString(arrayName). Is it like:

and then I recall it like:

but the result is just like original toString without any own modification.
What am I doing wrong?

cheers
 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You probably imported the java.util.Arrays class and called its toString(double[]) method, which can not be overridden. toString(double[]) is a static method of the Arrays class. Static methods can't be overridden (only hidden). Arrays also doesn't have an accessible constructor, so you can't extend it.

You should name your class something different than Arrays, and you should make the methods static. If it's a utility class, give it a private constructor without parameters and an empty implementation.
 
Przemek Geminski
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks a lot.
 
Przemek Geminski
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
overriting just simply toString() without any parameter inserted gives the desired effect.

and


returns what I want ([5.403208456693433* , 4.094773757770066* ,.. and so on).

 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad you figured it out
reply
    Bookmark Topic Watch Topic
  • New Topic