Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
public MakeConnection(String type, ArrayList<ConnecInfo> listHops)
        {
if(type.contains("SSH"))
            {
                System.out.println("MakeConnection using a list of hops : type = SSH");
                this.auditClient = new AuditSSHClient(listHops);
            }
            else
            {
                if(type.contains("TELNET"))
                {
                    System.out.println("MakeConnection using a list of hops : type = TELNET");
                    this.auditClient = new AuditTelnetClient(listHops);
                }
                else
                {
                    System.out.println("MakeConnection using a list of hops : type = NULL -> TELNET");
                    this.auditClient = new AuditTelnetClient(listHops);
                }
            }
}

Bonjour, je suis débutant en java et je tombe sur un problême de syntaxe avec un switch(). J'aimerai transformer ce qui est au dessus pour utiliser un switch puisque j'ai d'autres cas à envisager. Je tombe sur un problême : il ne veeut pas du switch(type) ?

Merci de votre aide

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
public MakeConnection(String type, ArrayList<ConnecInfo> listHops)
        {
 
            switch(type)
            {
                case "SSH" : 
                    System.out.println("MakeConnection using a list of hops : type = SSH");
                    this.auditClient = new AuditSSHClient(listHops);
                    break;
                case "TELNET" :
                    System.out.println("MakeConnection using a list of hops : type = TELNET");
                    this.auditClient = new AuditTelnetClient(listHops);
                    break;
                case "ATDT" :
                    System.out.println("MakeConnection using a list of hops : type = ATDT");
                    break;
                default :
                    System.out.println("MakeConnection using a list of hops : type = TELNET");
                    this.auditClient = new AuditTelnetClient(listHops);
                    break; 
            }