java - Incompatible type error when attempting to use variable length argument -


i attempting use variable length argument in constructor, error messages:

  1. 'incompatible types string cannot converted int'

  2. illegal start of operation, ';' expected

    public class personnel {  private string pname; private string rank; private string certs [];  public static int totalpersonnel = 0;  public personnel(string name, string rank, string... certs) {      this.pname = name;     this.rank = rank;     this.certs =  certs;      incrpersonnel();  }  public static void incrpersonnel(){     totalpersonnel++; }  public static void main(string myargs[]){     personnel alex = new personnel ("alex", "cpt", ["none"] ); 

    }

    }

if try pass array way using not correct instead have use new string[]{"none"}, code should :

public static void main(string myargs[]) {     personnel alex = new personnel("alex", "cpt", new string[]{"none"});   } 

or can use :

public static void main(string myargs[]) {     personnel alex = new personnel("alex", "cpt", "val1", "val2", "val3");     //--------------------------------------------[_____________________] } 

but in case pass 1 value, don't have use new string[]{..}, need pass :

personnel alex = new personnel("alex", "cpt", "none"); 

if don't want pass value, don't need specify can pass first , second value :

personnel alex = new personnel("alex", "cpt"); //------------------------------------------^____no need pass 

it return empty array


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -