Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Just a simple doubt  RSS feed

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
Can you please tell me if we can do this:
From my first java class,I create an object reference to the second class and call a method of that class eg.

I know under normal circumstances this would throw a null pointer exception as I need to do something like this;

But is it possible to use Reflection or some other technique to accomplish the first thing???
Thanks
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you already tried yourself the first snippet and it threw NullPointerException. The only difference with using reflection it that it will work with a null reference if the method is static. If not static - you will get the exception again.
 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Buddy,
But the method is not static...so as you say there's probably no other way to do such thing.
Thanks
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!