• Post Reply Bookmark Topic Watch Topic
  • New Topic

@Override toString(double[] a)  RSS feed

 
Przemek Geminski
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • 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
 
Stephan van Hulst
Saloon Keeper
Posts: 7992
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Ok, thanks a lot.
 
Przemek Geminski
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • 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: 7992
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad you figured it out
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!