Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Is instanceof and getClass similar?

instanceof similar
0
Posted

Is instanceof and getClass similar?

0

No, they are not the in the sense that the instanceof refers to an operator whereas the getClass refers to a method, usually of the class java.lang.Object class. Take into consideration a scenario where if(o.getClass().getName().equals(“java.lang.Math”)){ } is used, the only check by this method is whether we have passed a classname equal to java.lang,Math, the class java.lang.Math is loaded by the bootsrap classLoader of which is an abstract class. The responsibility of a classLoader is definitely to load classes and all objects of the given classes have references to this classLoader. Returning of the runtime class of object is performed by the getClass method by fetching the instance of java for a type name, which has been qualified fully. The code which we wrote is of no significance as we arent supposed to compare getClass.getName(). This is because if two separate class loaders load the same class, Java Virtual Machine will consider them as separate classes. The only thing it can

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123