Dear Sir i was about to ask you that i want to design my method that it should take all primitive data types as parameters and it should be of that type only inside the method.this concepts is used in C++ as templates
santhosh.R gowda wrote:
Please read this carefully
want to know the method like that takes all primitive values as parameter
You really need to work on your communication skills.
Like Campbell said, your original post is very confusing.
Nitish posted a probable solution based on what he could make of it. He was also kind enough to ask you, if he understood your problem correctly.
If it was clear he you had not managed to convey the meaning properly, re-quoting your original post hardly helps clear out the meaning does it?
Also, "please read this carefully" implies that the fault is on Nitish's part, of giving your post a cursory glance, which is not the case.
Please make sure people understand your posts and are not offended.
The easiest option is probably with Method Overloading -- but technically, that isn't "one method". Another option is to have the method take an Object parameter, and rely on autoboxing to allow the method to be called with primatives.
Ya i agree with you but taking as Object as a parameter will convert primitive to object .
i want exactly like this in primitive
Nope. Won't work. There is no option to have a single method take multiple primative types -- as primatives. If you want to provide this option to your callers, you have to do some work -- either create a bunch of overloaded methods, or type and unbox the object back to primative. There is nothing in the current specification that will allow you to do it without doing some work.
As examples, (1) take a look at the printstream println() methods to see a bunch of overload methods, or (2) take a look at the printf() method to see the autoboxing option. Both provide the "feel" of a single method taking any primatives.