This is partial Java code:
private static void printAddressInfo(String name, InetAddress... hosts) throws Exception How does one convert the "InetAddress... hosts" to NetRexx syntax for the method, such as, method printAddressInfo(name=String, ........) signals Exception And also for this piece of Java code: for(InetAddress host : hosts) I'd guess a loop in NetRexx but unclear how it would syntactically look? |
The ... syntax in Java is really just shorthand for passing an array so: private static void printAddressInfo(String name, InetAddress... hosts) could be converted to method printAddressInfo(name = String, hosts = InetAddress[]) private static Here's a worked example: Java import java.net.InetAddress;
public class TJDotty { public TJDotty() {
return; } private static void printAddressInfo(String name, InetAddress... hosts) { System.out.println(name);
int ix = 0; for (InetAddress host : hosts) { ix += 1;
System.out.printf("%03d: %s%n", new Integer(ix), host.toString()); }
return; } public static void main(String[] args) { try {
InetAddress localHost = InetAddress.getByName("localhost"); InetAddress googleHost = InetAddress.getByName("google.com");
printAddressInfo("Hosts", localHost, googleHost); }
catch (Exception ex) { ex.printStackTrace(); }
return; } }
NetRexx /* NetRexx */ options replace format comments java crossref symbols nobinary
import java.net.InetAddress
RexxMain(arg)
return method printAddressInfo(name = String, hosts = InetAddress[]) private static
say name ix = 0
loop host over hosts ix = ix + 1
System.out.printf("%03d: %s%n", [Object Integer(ix), host.toString()]) -- simulate the ... syntax for printf end host
return
method RexxMain(arg) public static do
localHost = InetAddress.getByName("localhost") googleHost = InetAddress.getByName("google.com")
printAddressInfo("Hosts", [InetAddress localHost, googleHost]) catch ex = Exception
ex.printStackTrace end
return Output (from both programs): On 22 October 2013 12:38, gpatrick <[hidden email]> wrote: This is partial Java code: Can't tweet, won't tweet! _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
Alan
-- Needs more cowbell. |
Free forum by Nabble | Edit this page |