• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting Null Type for Parameters  RSS feed

 
Shashank Sharma
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey can anyone please tell me how can I set parameter type as NULL ;
we can do Integer.TYPE for parameters
 
Zandis Murāns
Ranch Hand
Posts: 174
Java Java ME Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error does it gives? I see no reason for giving error.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can just do

Or is this not what you mean? What is the error that you get? Can you please explain a bit more of the context of this problem: what are you using this code for?
 
Shashank Sharma
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


it gives java.lang.noSuchMethodException



I am trying to implement reflection to invoke a method ;
above code works fine for a method with a parameter like setId(int )
as the parameter type can be set to Integer.TYPE
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The getInfo method you are trying to call via reflection has no arguments. So why then are you trying to find the method as if it has one argument, where you set the type of that argument to null? Just don't pass any argument types to Class.getMethod:

 
Shashank Sharma
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!