0
To what extent a reference to an object is exactly equal to it?
I’ll explain my situation:
Within a Adapter, i need to print a particular item in a list. The criterion for coloring that item is in an object that is outside my Adapter.
This object is a map with the relationship between users and channels in an IRC network. And the criterion is the level of the user in the channel.
If I had an instance of the channel class inside the Adapter, it would help me a lot, but how to know if this instance will accurately reflect the channel status within the IRC client?
The channel is obtained as follows:
// objeto que mapeia usuarios-canais
UserChannelDao dao = ircClient.getUserChannelDao();
// objeto que representa o canal
Channel canal = dao.getChannel("#canal");
It is safe to keep a channel object inside the Adapter?
Normally [i.e. from the language point of view] having one, two, several references to the same object simply means that there is only one object - references are simply copies of memory address of that object. That is, if you touch the object, it will be touched, and whatever reference you use to query it it will find this object in its updated state. I’m not going to post this as an answer, though, because I don’t know the situation specific of the mentioned objects (because one thing is language, another is the structuring of the Android platform).
– mgibsonbr
@mgibsonbr +1. I don’t know what API you’re using to interact with IRC, but I believe you’ll need to update your list when a user enters or leaves for example. Check in your API if it doesn’t let you register listeners for events, for example "Onuserleftchannellisterner". You implement it on your Adapter and when something actually happens, you update your list.
– wryel
If the reference was equal to the object, it would not be a reference ;)
– Oralista de Sistemas
Got it. So I’m going to store the Channel object inside the Adapter.
– Informatheus