• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to send class as a parameter  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello;

I found this in a tutorial and wanted to turn it into a function:






any thoughts?

thanks,
dsdsdsdsd
 
Saloon Keeper
Posts: 7994
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shannon, welcome to CodeRanch!

I'm not sure why you want to make a method out of it. You can simply do the following instead:

String.class.getInterfaces(); or
Integer.class.getInterface(); etc.

 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you did want to make a method of of it for some reason, then what you've done isn't quite right. ClassName.class is what's known as a "class literal", and gives you a Class object from the class name. So argo.class wouldn't work - it would be trying to create a Class object from a class called "argo". But argo is an argument, not a class name.

You could do:
(not sure what your "om" prefix is adding)

Or, better (because Class uses generics):

But really, as Stephan says, there isn't any point. You're just duplicating the method that's already there.
 
shannnon burnett
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm only doing it for the sake of experiment ... to see what I can and cannot do

A string literal (e.g. "I am a string.") is a notation which represents an instance (object) of the class String,
A class literal (e.g. Hashtable.class) is a notation which represents an instance (object) of the class Class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!