• Post Reply Bookmark Topic Watch Topic
  • New Topic

Casting warning  RSS feed

 
Ajmer Singh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

code of stack.java is given below. please give me write choice to use this code
 
Viktor Logwin
Ranch Hand
Posts: 99
15
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search for the question "How to create a generic array in Java?" on stackoverflow.
There is a nice answer to your question.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You don't have anything wrong; this is one of the few instances where the annotation is called for. Precede that method/constructor with
@SuppressWarnings("unchecked")
More details in the Java™ Tutorials.
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That code is wrong because an Object[] is NOT a T[].

Instead, to implement a collection based on an array, you should use an Object[] and then cast the individual elements before you return them to the client:
 
Ajmer Singh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Viktor Logwin wrote:Search for the question "How to create a generic array in Java?" on stackoverflow.
There is a nice answer to your question.



Thank you for reply..but i am new to java if possible do provide me necessary changes in the above code
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ajmer Singh wrote:
Thank you for reply..but i am new to java if possible do provide me necessary changes in the above code


Stephan already did that in the previous post.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!