• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Method that take all primitive values..?

 
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Marshal
Posts: 76825
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
It's exactly the same and completely different as this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic