Generate Get and Set methods for Java in perl

Aug 05, '02 08:30:12AM

Contributed by: Accura

I find it a pain when writing java code to type out 20 or 30 get set methods (since you sould use get and set in java instead of referring straight to the variable) so i wrote a perl scrpt that does this for me.

Here it is.

#!/usr/bin/perl
($a, $t) = @ARGV;
unless ($a)
{
print "Nameov integer: ";
chomp($a = <STDIN>);
print "Type of integer:";
chomp($t = <STDIN>);
$b = ucfirst($a);
}
print "\npublic $t get$b()\n{\n";
print "\t return $a;\n}\n\n";
print "pubic void set$b($t val)\n{\n";
print "\t $a = val;\n}\n\n";
[Editor's note: This hint has not been tested on my machine, primarily because my skill set does not extend to Java and perl!]

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20020805083012902