Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2001
    Messaggi
    82

    [JAVA] Hashtable e put - 1 warning

    Ciao, stò facendo un mini programmino in java per testare una cosa eppure ho qualche problema in fase di compilazione (nulla di che, un warning, eppure mi stà facendo andare in bestia)...

    Qualcuno ha qualche idea?

    Ecco il codice:

    codice:
    //server di comunicazione
    
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.text.DateFormat;
    
    class server {
    	public static void main (String args[]) throws Exception {
    		ServerSocket server = null;
    		Socket client = null;
    		ThreadTCP t;
    		Hashtable hashtbl = new Hashtable();
    
    		try
    		{
    			server = new ServerSocket(7000);
    		}
    		catch (IOException e){}
    		while(true)
    		{
    			client = server.accept();
    			t = new ThreadTCP(client, hashtbl);
    			t.start();
    		}
    	}
    }
    
    //rendere multithread
    class ThreadTCP extends Thread {
    	
    	private Socket thread_client = null;
    	//User tmp = null;
    	private Date now = new Date();
    	private Hashtable onuser = new Hashtable();
    
    	public ThreadTCP(Socket client, Hashtable hashtbl)
    	{
    		this.thread_client = client;
    		this.onuser = hashtbl;
    	}
    
    	public void run()
    	{
    		try
    		{
    			String strng_client, frase_server;
    			InetAddress tmpip = null;
    			String tmp = new String("testo a caso");
    			BufferedReader from_client = new BufferedReader(new InputStreamReader(thread_client.getInputStream()));
    			strng_client = from_client.readLine();
    			tmpip = thread_client.getInetAddress();
    			System.out.println(tmpip + " connesso " + DateFormat.getTimeInstance(DateFormat.SHORT).format(now));
    			if(onuser.contains(tmpip)){
    				System.out.println("gia connesso");	
    			}
    			else {
    				System.out.println("connettiti");
    				onuser.put(tmp, tmpip);
    			}
    			frase_server = strng_client.toUpperCase();
    			DataOutputStream server_out = new DataOutputStream(thread_client.getOutputStream());
    			server_out.writeBytes(frase_server + '\n');
    		}
    		catch (IOException e) {}
    	}
    }
    Il warning è il seguente:

    codice:
    server.java:82: warning: [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.Hashtable
                                    onuser.put(tmp, tmpip);
                                              ^
    1 warning
    Qualche idea???
    [TrGh]

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2004
    Messaggi
    724
    presuppongo che tu abbia compilatocon -Xlint e il warn che ti da dovrebbe essere dato dal fatto che i valori passati alla put non sono mai stati specificati.
    in teoria risolvi risolvi mettendo

    private Hashtable <Object>onuser = new Hashtable<Object>();

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.