Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an arraylist that I want normal users to only be able to GET information from and then I have an administrator account that I want to be able to do SET, SORT, and other methods to the arraylist. How do I share this array list with my administrator account and normal user accounts while also having different functionality to users depending on who they are. I guess I am asking how to add new methods to a class from a subclass. Please tell me the pros and cons to the way you go about solving my problem. The reason I don't have any code right now is because I am in the planning phase of my project and I just need to know if this is possible. Thanks!

share|improve this question
1  
What have you tried (include some code)? What problems are you seeing? –  Taylor 1 hour ago
 
Yes, please elaborate a little more: what is the context of your application? Are we on the web, is this a desktop app? –  theSilentOne 1 hour ago
 
This is just an Android application. sorry, I thought I added that tag –  Jordan Hochstetler 52 mins ago
 
TAgging it android doesn't really substitute for what you've tried and the problem(S) you're seeing. –  Taylor 49 mins ago
 
Is there anything I can do with interface or abstract to share my arraylist? See I am in the planning phase of this project and I just need to know what is possible. –  Jordan Hochstetler 13 mins ago

2 Answers

You can return a Collections.unmodifiableList() for the underprivileged consumers.

share|improve this answer

You can make a list readonly by using Collections.unmodifiableList()

You don't give much details in your question, but here is an example of how it could work. Assuming that you have an object that allows you to get a hold of an array based on a UserType enum:

public List<Object> getMyArray(UserType type) {

    if (type == UserType.ADMIN) {
        return _myList;
    }
    else {
        return Collections.unmodifiableList(_myList);
    }
}
share|improve this answer
 
This is close. Is there anything I can do with interface or abstract to share my arraylist? See I am in the planning phase of this project and I just need to know what is possible. –  Jordan Hochstetler 16 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.