• Post Reply Bookmark Topic Watch Topic
  • New Topic

Method that take all primitive values..?  RSS feed

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all i want to know the method like that takes all primitive values as parameter and it should print that value inside the method...Please let me know
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well taking all primitive values.....you can use var-args but this will allow on one type of primitives and print it using the index of the value like


I hope this is what you are talking about.....
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitish wrote
I hope this is what you are talking about.....

Please read this carefully
want to know the method like that takes all primitive values as parameter
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The original question is not clear, but I think you ought to be showing us what you think you ought to write. Please have a quick look at some of our FAQ, Santosh_R Gowda.
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The original question is not clear

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
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
santhosh.R gowda wrote:
Please read this carefully
want to know the method like that takes all primitive values as parameter


Santosh,
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.
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

Henry
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!