• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

JDK 1.5 warnings during build

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

A quick question.
I am getting a number of warnings while building with JDK 1.5 pe code snippet below

cast to java.lang.Object for a varargs call
cast to java.lang.Object[] for a non-varargs call and to suppress this warning
return MessageFormat.format(message, new String[] {argument});

I did attempt changing this new String to new Object however this breaks my code.

Is is safe to leave these warnings in there or should I be doing something after changing it to new Object[]?

Thanks,
S
 
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With varargs, Object... means Object[]. Unfortunately, if you pass an array other than Object[] it will give you this warning. The reasons is that String[] is also an Object.

The safest way is just cast to Object[]:


However, in this case you can just omit creating the new array and just use varargs directly:


And you do know that Object[] can also contain String objects, don't you? So I see no reason why changing this anonymous String[] into Object[] would break any code. You don't use it anywhere else.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic