How do I disambiguate in Scala between methods with vararg and without

后端 未结 5 1765
无人及你
无人及你 2020-11-30 08:30

I\'m trying to use the java jcommander library from Scala. The java JCommander class has multiple constructors:

 public JCommander(Object object)  
 publi         


        
5条回答
  •  悲&欢浪女
    2020-11-30 09:09

    I think your easiest option is to have a Java class with a factory method to bridge the issue:

    package com.beust.jcommander;
    
    public class JCommanderFactory {
        public static createWithArgs(Object cmdLineArgs) {
            return new JCommander(cmdLineArgs);
        }
    }
    

    Alternatively you could use http://jewelcli.sourceforge.net/usage.html instead. JewelCli has an unambiguous factory method for the same purpose and also uses PICA (Proxied Interfaces Configured with Annotations) technique http://www.devx.com/Java/Article/42492/1954.

    In fact I have an example of using JewelCLI with Scala here on Stack Overflow.

提交回复
热议问题