• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

is there any way pass arguments to class method without overloading ?

 
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all
i have simple class say : ( note this is not valid java syntax only to explain my problem )
public class Foo{

private String s = "";

private String ss = "";

private int i = 0;


public String get(somekind Of Type arg[]){

s = arg[0];

ss = arg[1];

i = arg[2];

return "Done";

}


}

now the function call

Foo foo = new Foo();

foo.get();

foo.get("my");

foo.get("my","name");

foo.get("my,"name",1);



now i know if i would like it to work i had to do in my class method overloading , but is there any way to avoid it?

you see the variables already have default values so if they don't get filled with the method args they will have something .

thanks
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you adverse to overloading? This is a situation where it makes sense:
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Meir Yan :
you see the variables already have default values so if they don't get filled with the method args they will have something .



Since in the method argument, you are changing the value of each instance variables, why don't you assign them in constructor by overloading the constructor.




Naseem
[ August 04, 2006: Message edited by: Naseem Khan ]
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well this is one of my many problems im facing to convert some in house server scripting lang to jsp
this involved allot of pages to convert ( 1000 +) and im trying to avoid how much then i can to do modification to the original code .. any way in this in house script land i can call function like that :

fn.myFunc
or
fn.myFunc("name");
or
fn.myFunc("name",1,3);
and so on ....
this function can take up to 10 arguments or less , im trying to avoid the need to write 10 functions in my class for every types .
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

avoid how much then i can to do modification to the original code

Why? Scripting languages aren't Java. The little scripting I have done, I get the impression that scripting languages are not even object oriented. So why are you translating the old system? Have a good look at its functionality and then decide that translating the old system really is easier than writing a new fully OO system.
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why not, the impression i got from jsp that i can implant OO and java principles
this jsp do have strong possibilities not like simple scripting lang
i did build complex class's already in jsp .
 
Dana Bothner-By
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Meir Yan:
well this is one of my many problems im facing to convert some in house server scripting lang to jsp.



My friend, you may get much citicism because of that statement. Badly written code often happens when people try to do it all in JSP. Ideally, you should be separating the presentation (JSP) from the rest of the application code. So are you? If not, things can get messy.
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic