[eside-ghost] Java y punteros!!!

Marcos López marcosl en euskalnet.net
Vie Ene 20 09:33:07 CET 2006


Yeup

2 cosillas:

Yo creo que la Maquina Virtual intentará evitar que se acceda a la
dirección física donde reside dicho objecto. Su misión es la de
abstraerse del Sistema Operativo en el que esté corriendo. Por ello creo
que el toString() no va a funcionar para esto.

Y la otra cosa es que hay muchos Objectos que reimplementan el
toString(). Por ejemplo, si a un Integer le llamas a este método, no
sacará el hashcode sino que devolverá el int que guarde dentro.

Un saludete


El vie, 20-01-2006 a las 09:06 +0100, Uvatha escribió:
> Wop!
> 
>    Me han llegado los mensajes en desorden, y creo q m he enterado de
> la mitad xDD. El numerito q sale en un toString() de la clase Object
> es un hashcode q se utiliza para el método equal(), q dice si dos
> referencias apuntan al mismo objeto (hablando siempre de la
> implementacion de Object, otras clases como String tienen su propia
> implementacion). Si mi cerebro no falla a estas horas de la mañana (no
> es q funcione mucho mejor el resto del dia xD), lo q obtendreis en
> esas lineas no es exactamente la direccion de memoria, si no el
> hashcode del objeto. Lo q no tengo ni idea es si se puede obtener la
> direccion de memoria de un objeto.
> 
>   Lo más importante ¿q quereis hacer? Es MUY raro q se necesite la
> direccion física de un objeto...(una de las ventajas de Java era
> ahorrarse cosas de este estilo q tanto odio del C y C++).
> 
> 
>     La verdad es q el inglés de esta parte de la docu d e la API es un
> poco lioso, lo copy pasteo para q cada uno saque sus propias
> conclusiones.
> 
> Nus vemos. Aiooooooooooooooo
> 
> El toString() de un Object saca esto por pantalla:
> getClass().getName() + '@' + Integer.toHexString(hashCode())
> 
> public int hashCode()
> Returns a hash code value for the object. This method is supported for
> the benefit of hashtables such as those provided by
> java.util.Hashtable. 
> The general contract of hashCode is: 
>       * Whenever it is invoked on the same object more than once
>         during an execution of a Java application, the hashCode method
>         must consistently return the same integer, provided no
>         information used in equals comparisons on the object is
>         modified. This integer need not remain consistent from one
>         execution of an application to another execution of the same
>         application. 
>       * If two objects are equal according to the equals(Object)
>         method, then calling the hashCode method on each of the two
>         objects must produce the same integer result. 
>       * It is not required that if two objects are unequal according
>         to the equals(java.lang.Object) method, then calling the
>         hashCode method on each of the two objects must produce
>         distinct integer results. However, the programmer should be
>         aware that producing distinct integer results for unequal
>         objects may improve the performance of hashtables. 
> As much as is reasonably practical, the hashCode method defined by
> class Object does return distinct integers for distinct objects. (This
> is typically implemented by converting the internal address of the
> object into an inte ger, but this implementation technique is not
> required by the JavaTM programming language.) 
> 
> 
> Cymo <gcymoril en gmail.com> escribió:
>         > Hay clases en java que te permiten escribir en vez de en
>         consola, en
>         > un StringBuffer o un CharArray ?? ahora no me acuerdo, y eso
>         luego lo
>         > pueses convertir en una cadena...
>         >
>         Me autocontesto:
>         
>         Un PrintStream es un objeto que "escribe" cosas, es decir,
>         tiene el
>         método print (como System.out.print()
>         
>         Un ByteArrayOutputStream usa internamente un buffer
>         (accesible),
>         siendo el buffer un array de bytes (byte [] buf).
>         
>         Así que se me ocurre:
>         
>         
>         PrintStream kapi = new PrintStream(
>         new ByteArrayOutputStream( 1024 );
>         
>         kapi.print( variable ); // la direccion queda "impresa" en el
>         buffer interno
>         
>         Strin g direccion = kapi.toString(); // el método toString()
>         devolvería el buffer pasado a String
>         _______________________________________________
>         eside-ghost mailing list
>         eside-ghost en deusto.es
>         https://listas.deusto.es/mailman/listinfo/eside-ghost
> 
> 
> 
> 
> //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
> 
> "Take a look to the sky just before you die
> It's the last time he will
> Blackened roar, massive roar, fills the crumbling sky
> Shattered goal fills his soul with a ruthless cry
> Stranger now are his eyes to this mystery
> He hears the silence so loud
> Crack of dawn, all is gone except the will to be
> Now they see what will be, blinded eyes to see"
> 
> For Whom The Bell Tolls. James Hetfield.
> 
> //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
> 
> 
> ______________________________________________________________________
> 
> LLama Gratis a cualquier PC del Mundo.
> Llamadas a fijos y móviles desde 1 céntimo por minuto.
> http://es.voice.yahoo.com 
> _______________________________________________
> eside-ghost mailing list
> eside-ghost en deusto.es
> https://listas.deusto.es/mailman/listinfo/eside-ghost



Más información sobre la lista de distribución eside-ghost