Re: New File with a Directory
- From: Lew <lew@xxxxxxxxxxxxx>
- Date: Sun, 30 Dec 2007 22:01:01 -0500
Alan wrote:
If I replace
File file = new File(infile.getName());
with
File file = new File(infile.getPath());
in the "methodWithNew" method, then it works.
So, I guess the bottom line is that I can just set a File object
to the input File object, without needing to use the "new" operator.
When I do that (no "new"), am I just making the [not] new File object in
the method point to the input File object? This sounds OK to me.
You're making the variable 'file' point to the same object as 'infile'.
This sets the variable 'file' to point to the same File object as 'infile', yes. It is, however, not a "new File object", nor is an object ever made to point to an object. Objects reference other objects through variables.
File file = infile;
It is the variable 'file' that points to an object, and the variable 'infile' that points to the same object. There are two variables, pointing to only one object.
File file = new File( infile.getPath() );
Now the variable 'file' points to a different File object from 'infile'. There are two variables, pointing to two different objects.
--
Lew
.
- References:
- New File with a Directory
- From: Alan
- Re: New File with a Directory
- From: Mark Thornton
- Re: New File with a Directory
- From: Lew
- Re: New File with a Directory
- From: Mark Thornton
- Re: New File with a Directory
- From: Alan
- New File with a Directory
- Prev by Date: Re: Great SWT Program
- Next by Date: Re: Great SWT Program
- Previous by thread: Re: New File with a Directory
- Next by thread: Use of AssertionError
- Index(es):