• Post Reply Bookmark Topic Watch Topic
  • New Topic

retrieve object from Vector  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it sounds simply, i try to retrieve an object from a Vector, but do not understand why i get an error:




 
Ranch Hand
Posts: 550
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not see any error in your code (except that you typecasting could be a problem. But you mentioned that too in comments). What error are you seeing ?
 
Stefan Müllerheim
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, the problem sat again in front of the screen.

braces were wrong.
 
Sheriff
Posts: 21137
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right. You can't add statements directly inside classes, only inside methods, constructors and instance/static initializer blocks.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Muellerheim wrote:

Will not work because a non-generic Vector will return an Object. Your commented line will fix this. Another solution would be to make the Vector generic. You can read all about generics in the Java Generics Tutorial.

Are you sure you want to use a Vector and not an ArrayList? The classes do the same but the methods of the Vector are synchronized so worse performance but with thread-safety.
The Java Naming Convention dictates that class names should start with a capitalized letter so test1 should be Test1.
 
Kumar Raja
Ranch Hand
Posts: 550
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Muellerheim wrote:ok, the problem sat again in front of the screen.

braces were wrong.


I think I need to start using another pair of eyeglasses now. I too did not notice that error
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kumar Raja, try to compile the example and you will see! There should be something like this, ans I'd recommended to use generics:


Also please start your classes with the capital letter!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!