Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Aliasing

 
Stephen Silva
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aliasing also can happen within method calls, the following program illustrates it. Identify
the problem and modify the program to address the aliasing.

class Letter {
char c;
}
public class PassObject {
static void f(Letter y) {
y.c = z;
}
public static void main(String[] args) {
Letter x = new Letter();
x.c = a;
print("1: x.c: " + x.c);
f(x);
print("2: x.c: " + x.c);
}
}

Can somebody please, explain me what is aliasing and solution to this problem.

Thanks.
 
Prabhjot Jassal
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't think it would compile as you are trying to access, char c which is an instance variable in static method.
 
Stephen Silva
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

It compiles with slight modifications to the code.
class Letter{
char c;
}

public class PassObject {

static void f(Letter y){
y.c='z';
}

public static void main(String[] args) {
Letter x=new Letter();
x.c='a';
System.out.println("1: x.c "+x.c);
f(x);
System.out.println("2: x.c "+x.c);
}

But I want to know how to address the issue aliasing in this programme
 
Hasanka Sandujith
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will give some idea... I think
Aliasing
 
Stephen Silva
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks

Need to know what the aliasing is in this programme and What does that really expect to do?
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suneth, we don't have too many rules around here, but we do ask that you BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/new-java/48162-aliasing-methods.html
 
Stephen Silva
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I don't know about that post.
But I am in need of having an idea about aliasing to answer this question.

I know it's your valuable time that you spend to answer these questions.
I always respect that.

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic