• Post Reply Bookmark Topic Watch Topic
  • New Topic

JDK 1.5 warnings during build  RSS feed

 
Sharon Cleary
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!