Article View: es.comp.lenguajes.java
Article #26142Re: int e Integer
From: Jos� Antonio P�rez Testa
Date: Thu, 04 Feb 1999 00:00
Date: Thu, 04 Feb 1999 00:00
73 lines
2797 bytes
2797 bytes
This is a multi-part message in MIME format.
--------------71C6AB6845CAD8FB64E4EE6C
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Supongo que tu pregunta es de tipo filos�fico, pero yo lo que har�a es que la
funcion devuelva el nuevo objeto
public static Integer prueba(Integer j){
...
return j;
}
...
i=prueba (i);
victor wrote:
> Hola compa�eros!
>
> Tengo un peque�o problemilla con las classes wrapper y el paso de argumentos
> por referencia.
>
> Si definimos una variable int en un m�todo, llamamos a un nuevo m�todo con
> esta variable como argumento y queremos que esta llamada modifique el valor
> en el m�todo inicial s�lo podemos hacerlo si encapsulamos la variable en un
> objeto Integer.
>
> Ahora bien, de un objeto Integer puedo consultar su valor (intValue), �pero
> c�mo puedo actualizarlo? No hay ning�n m�todo para hacerlo, y si lo que hago
> es un new Integer(), el nuevo objeto creado no me sustituye al anterior.
>
> Ah� va un ejemplo:
>
> public class Params {
>
> public static void prueba(Integer j){
> //j = j * 2; debo recuperar el valor int de j
> //j = j.intValue()*2; no puedo asignarlo a j!
> j = new Integer(j.intValue()*2); /*el nuevo objeto es <>
> de i y no se
> modifica!*/
> // necesitar�a un j.setValue(int)
> System.out.println("parametro * 2: " + j);
> }
>
> public static void main (String args[]) {
> Integer i =new Integer(5);
> prueba(i); //i=5
> System.out.println("Resultado prueba:" + i); //quiero que i=10
>
> }
> }
>
> Gracias!
--------------71C6AB6845CAD8FB64E4EE6C
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Jos� Antonio P�rez Testa
Content-Disposition: attachment; filename="vcard.vcf"
begin: vcard
fn: Jos� Antonio P�rez Testa
n: ;Jos� Antonio P�rez Testa
org: Grupo Polar
email;internet: testa@polar.es
tel;work: 91-515 37 88
x-mozilla-cpt: ;0
x-mozilla-html: FALSE
version: 2.1
end: vcard
--------------71C6AB6845CAD8FB64E4EE6C--
Technical Details
Message-ID:
<36B9A1CC.66F7DFA6@polar.es>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7947eh$mjj$1@eubuf21.eu.concert.net>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: 1116f3,1691d5e12cfe717a X-Google-Attributes: gid1116f3,public From: "Jos� Antonio P�rez Testa" <testa@polar.es> Subject: Re: int e Integer Date: 1999/02/04 Message-ID: <36B9A1CC.66F7DFA6@polar.es> X-Deja-AN: 440593969 References: <7947eh$mjj$1@eubuf21.eu.concert.net> To: victor <victor@cfdti.com> Content-Type: multipart/mixed; boundary="------------71C6AB6845CAD8FB64E4EE6C" Organization: Grupo Polar Mime-Version: 1.0 Newsgroups: es.comp.lenguajes.java