Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-16-2004, 01:54 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
assign a value to 'this'

can you tell it's a java day for me? =)

i have a class called 'agent'

check out this code:
Code:
public agent(int agentID){
  agent a = AgentUtility.getAgentByID(agentID);
  this = a;
}
this code won't work because i can't assign a value to 'this' .. is there any way i can do this without having to go through each of 'this' properties and assign the value of 'a' properties?
__________________
Mike
sde is offline   Reply With Quote
Old 06-16-2004, 03:11 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,139
Belisarius is on a distinguished road
Nope.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 06-16-2004, 03:14 PM   #3 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,139
Belisarius is on a distinguished road
To be a bit more helpful, I think your problem is a matter of abstraction. You probably don't want to be getting an Agent in this fashion.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 06-16-2004, 03:29 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
ok thanks.

i just wanted to be able to instantiate an agent, but all my data handling is in the agent utility class. i think i see your point though. it is a bit redundant.
__________________
Mike
sde is offline   Reply With Quote
Old 06-16-2004, 05:58 PM   #5 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
i think you missed the point. i will spell it out blatantly:

DO NOT attempt to modify the 'this' pointer under any circumstances.
i'm pretty sure that java won't let you do it (but c++ will). it is not a question of style, or even good programming methods, it is a programming error to modify the 'this' pointer.
joe_bruin is offline   Reply With Quote
Old 06-16-2004, 06:30 PM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
blatent is good. i thought i did this in c#, but i was wrong. i just tried it and it says 'this' is read-only.

thanks
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign value to a variable depending on time AOD PHP 10 02-12-2003 03:06 PM


All times are GMT -8. The time now is 01:43 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting