How can 1 make an object of user defined class immutable?

Hi All,
How can one make an object of user defined class immutable?
Whats the implementation logic with strings as immutable?
Regards,

Hi All,
How can one make an object of user defined class
immutable?The simple answer is you can't. That is, you can't make the object itself immutable, but what you can do is make a wrapper so that the client never sees the object to begin with.
A classic example of a mutable class:
class MutableX {
    private String name = "None";
    public String getName() {
        return name;
    public void setName(String name) {
        this.name = name;
}I don't think it's possible to make this immutable, but you can create a wrapper that is:
class ImmutableX {
    private final MutableX wrappedInstance;
    public ImmutableX (String name) {
        wrappedInstance = new MutableX();
        wrappedInstance.setName(name);
    public String getName() {
        return wrappedInstance.getName();
    // Don't give them a way to set the name and never expose wrappedInstance.
}Of course, if you're asking how you can make your own class immutable then the simple answer is to not make any public or protected methods that can mutate it and don't expose any mutable members.
Whats the implementation logic with strings as
immutable?
Regards,I don't understand the question.

Similar Messages

  • How to make an applet load user-defined package?

    How to have an applet load user-defined package?
    I have packages in their own directories, and the applet compiles and links with them, by use of CLASSPATH env variable. But when it comes time to run, it ignores that and does not know where the classes (in the packages) are.
    If I don't use packages and put all code in one directory, runs fine. If I use an application, I can link with and load my packages.
    I know applets can't use things like CLASSPATH for security reasons, but still, they should be able to be compiled out of several packages, why do I have to put all code together??

    OK, for reference for future newbies, here's the answer:
    use CODEBASE attribute in your html file (if on Windows server, don't use drive letter but relative path to .html file, Unix style, and put all your .class files beneath that, for example, in your .html file
    <applet
    CODEBASE="..\class
    and then have package bar Bar.class file, in ..\class\bar

  • How to Use Sequence Object Inside User-defined Function In SQL Server

    I'm trying to call sequence object inside SQL Server user-defined function. I used 
    Next Value for dbo.mySequence  to call the next value for my sequence created. But I'm getting an error like below.
    "NEXT VALUE FOR function is not allowed in check constraints, default objects, computed columns, views, user-defined functions, user-defined aggregates, user-defined table types, sub-queries, common table expressions, or derived tables."
    Is there any standard way to call sequence inside a function?
    I would really appreciate your response.
    Thanks!

    The NEXT
    VALUE FOR function cannot be used for User Defined function. It's one of the limitation.
    https://msdn.microsoft.com/en-us/library/ff878370.aspx
    What are you trying to do? Can you give us an example and required output?
    --Prashanth

  • How to make an Object common to all classes

    I am building an application.
    I need that one object (defined in the main class) be accesible to all other objects (classes). Also I need that any other object can change it.
    How can I do that without passing the object's reference around? Actually I pass the reference through a SET method in each object. This is tedious!
    Thanks a lot :)
    iCamps

    You could also create the Object using the singleton pattern. This way there is only one instance of the object, and every object that access it gets a reference to the same object.
    public class SingletonObject {
        private SingletonObject instance;
        static {
            instance = new SingletonObject();
        public SingletonObject getInstance() {
            return instance;
        private SingletonObject() {
            // Constructor
        public synchronized method1() {}
        public synchronized method2() {}
    }Then in your code access the SingletonObject like below. You can put a reference to the object in your constructor for each object that uses the SingletonObject, or jsut access it in the neccessary methods with SingletonObject.getInstance().
    public class YourClass {
        public void someMethod() {
            SingletonObject so = SingletonObject.getInstance();
            so.method1();
            so.method2();
    }

  • Some DB objects like User-defined datatypes being missed out?

    Dear all.
    I create an Oracle model for a captured SQL Server model and then right click -> click on 'Generate' to create the DB creation script.
    (1) But few objects like user-defined datatypes are missed out in the script.
    (2) Also, a simple stored proc as defined below missed out:
    CREATE PROCEDURE [SalesLT].[SayHi]
    AS
    SELECT 'Hi I am a job scheduler'
    GO
    Rgds, Abhi

    Hello,
    An OracleDI Dataserver connection to an RDBMS is, most of the time, defined with a single set of parameters: a user account name, a password and a URL.
    OracleDI may need to access numerous tables on the RDBMS which may not all be stored in the same database schema, catalog, library, ...and for which access privileges may not be identical.
    For this reason, it is necessary to ensure that the RDBMS user account has sufficient access privileges for these schema, catalog, librairies ...
    The user account should have at least read/right access permission for any OracleDI Physical Schema referenced for the concerned Dataserver (depending on the project within which it is used, a Physical Schema may store both source and/or target tables).
    Moreover, for project requirements, it may be necessary to use/create/drop certain RDBMS
    components such as stored procedures, views, temporary tables, system tables ...
    For this reason, make sure the user account referenced in the dataserver connection parameters is attributed sufficient privileges to any object it may manipulate with OracleDI.
    2nd point: you can use any logical name for the data server Name.

  • Object to user defined object

    I pushed user defined objects in to the Vector or Stack.
    But they return an java defined Object type when I try to use them.
    Is there way that I can convert this Object into my defined object.
    MyClass a;
    MyClass b;
    Stack table = new Stack();
    table.push(a);
    table.push(b);
    //now when i use pop to get it back it returns an Object type
    Object temp = table.pop();
    //how do I change this object into MyClass so i can have access to MyClass stuff?

    dam..thank you so much I feel stupid..Don't.
    Casting is one of those things that can take a while to get used to.
    In your original post, you asked: how do I change this object into MyClass so i can have access to MyClass stuff?
    It's important that you understand that casting doesn't change the object in any way.
    All it does is cause a reference that's been declared as one type to be treated as a different type. So even though all the compiler knows about what's returned from pop() is that it refers to an Object, you're telling it you know better, and that the object pointed at will in fact be a MyClass, and so you can access MyClass' members.
    If, at runtime, the object you happen to pop off the stack isn't a MyClass, casting won't magically turn it into one. You'll get a ClassCastException.

  • How can we get requester's user id using java code

    Hi,
    How can we get requester's user id using java code?
    eg: If i had logged in as xelsysadm and request a resource for user uid101 on the userid field it should display uid101 and not xelsysadm.
    also,
    I have a resoure "A" which on revoking should also revoke resources B and C. How can it be done. Resource A, B, and C are 3 different resource objects.
    ==Thanks,
    doki

    Ok, so there is a way, but it's not available during submission. You can use the findRequests api. From the result set, get the "Requests.Consolidated Data Value" value. In this information, you will get an xml formatted data. It provides the list of users on the request on the left side after submission. After the request is completed, this value is available. Upon completion, you could get the request information, get this value, and parse the information for user ids.
    In the same adapter, use the following API:
    formIntf.setObjectFormData(objInstanceKey, formHash)
    The formHash is a hashtable containing the field name on your object form, and the values you wish to populate it with. You could create a textarea box on your object form and populate the userids for who the request is for.
    However, this makes absolutely 0 sense. When you get a request, the list of userids are listed right there on the request.
    -Kevin

  • How can i create a new user in OID DIT tree programmatically  ?

    Dear All,
    How can i create a new user object in the OID DIT tree programmatically ?
    any help will be appreciated.
    Regards,
    Mohammed Amin

    Dear Eng. Jaime.. 
    Thank you so much  for replay...
    Can yon  explain 
    Do you want to create a contact in Jabber?
    Do you want to enable Jabber for a user?
    And what you meant last question..

  • How to make any object self-shining?

    hi,
    i guess thats an easy question, but i dont know where to look for the answer.
    so how to make any object self-shining like the infamous colorcube, so that one does not need to place any light?
    and am I right in my assumption that doing so will reduce the need of rendering power, since lights dont have to be computed?
    thanx,
    Usul

    I'm not sure what you mean here- if your object is lit then lighting will need to be calculated. If you don't want shapes to be lit, I think you can disable it by calling setLightingEnable(false) in their materials.

  • How to make an object mutable?

    Can any one tell me how to make an object mutable?
    Following is Class X & Y?
    class Y
    public static void main(String arg[]) {
    X a1=new X();
    Object a=a1.get();
    System.out.println(a.toString());
    a1.set(a);
    System.out.println(a.toString());
    class X implements Serializable
    public Object get(){
    return new Object();
    public synchronized void set(Object o)
    o=null;
    In my class Y when i say
    a1.set(a);
    I want local Object a of main method should be nullified.
    Can it be possible if yes what is the way or code to be applied so that
    my next a.toString() statement will give me NullpointerException.

    Isn't it more accurate to say that object references are passed by value?
    OP -- Basically you can't to what you want to do. When you "pass an object" as a method parameter, what you're really passing is a copy of the reference that points to the object. You now have two refs pointing to the same object--one in the caller and one in the method being executed. Setting either of those refs to null does NOT affect the object itself, and does NOT affect the other ref. It just means that the ref that's been set to null no longer points to any object.
    If you want the called method to make a change that the caller can see, you need to either 1) return a value from the method, 2) encapsulate the object to be changed as a member of new class, or 3) pass the object to be changed as the single element of an array. I would STRONGLY recommend against (3) as a way to simulate pass by reference. Better to examine your design and determine whether (1) or (2) more closely matches what you're really trying to accomplish.

  • How to make an object distributed across multiple jres?

    Hi,
    We used cache data mechanism for performance tuning. It will store data in static variable (Hashtable) and get initialized when app starts . We are using IPlanet Application Server and
    Using 6 KJS engines. This object ( Hashtable) is not distributed across all JRES.It has to reinitialize data again when request goes to any other KJS.
    We avoid sharing data in session and request, as data is huge.
    Can any one help us how to make this object distributed across all KJSs?
    Thanks in advance.
    raj

    We used cache data mechanism for performance tuning.
    It will store data in static variable (Hashtable) and
    get initialized when app starts.
    We are using IPlanet Application Server and
    Using 6 KJS engines. This object ( Hashtable) is not
    distributed across all JRES. It has to reinitialize
    data again when request goes to any other KJS.
    We avoid sharing data in session and request, as data
    is huge.
    Can any one help us how to make this object
    distributed across all KJSs?When you say 'initialized when app starts' do you mean iPlanets StartUp classes, rather than the Servlets init() ? Given a 'huge' dataset, avoid the latter.
    I'd suggest that a better approach is to implement this as an Entity Bean and accessed from Session bean and using Value Objects to return the data subsets.
    Checkout the Java Pet Store
    http://java.sun.com/blueprints/code/jps13/datasheet.html

  • HOw to make an Object oriented alv respond to double click

    Hi all,
    HOw to make an Object oriented alv respond to double click.SAmple code will be helpful.
    Thanks in advance,
    Alex.

    Hi,
    1. Create a Control (for Custom and Split Containers only)
    2. Instantiate a Container Object (in case of Custom and Split Containers, specify the control which is created by us in Screen painter) CREATE OBJECT
    3. Instantiate an Object of the kind of report that has to be displayed (List, Grid or Tree). CREATE OBJECT . Here we need to specify the Parent Container as the so that it sits in that container.
    4. Call appropriate methods to display the report on the screen. CALL METHOD ->
    DATA : g_dock TYPE REF TO cl_gui_docking_container,
    g_split TYPE REF TO cl_gui_easy_splitter_container,
    g_cont1 TYPE REF TO cl_gui_container,
    g_cont2 TYPE REF TO cl_gui_container,
    g_grid1 TYPE REF TO cl_gui_alv_grid,
    g_grid2 TYPE REF TO cl_gui_alv_grid.
    i_mara is an internal table of structure MARA
    SELECT * FROM mara INTO TABLE i_mara.
    i_kna1 is an internal table of structure KNA1
    SELECT * FROM kna1 INTO TABLE i_kna1.
    To create an Object of type Docking Container
    CREATE OBJECT g_dock
    EXPORTING
    side = cl_gui_docking_container=>dock_at_top
    extension = 200 .
    To Create an Object of Type Split Container. Here we can see that the Docking *Container Created above has been used as a parent .
    CREATE OBJECT g_split
    EXPORTING
    parent = g_dock
    orientation = 1 .
    Easy Split container splits one Control into 2 manageable controls, each of them is used * to handle one GUI Container each
    g_cont1 = g_split->top_left_container.
    g_cont2 = g_split->bottom_right_container.
    To Create an Object of type Grid . Here we can see that the Left Split Container * Created above has been used as a parent .
    CREATE OBJECT g_grid1
    EXPORTING
    i_parent = g_cont1 .
    To Create an Object of type Grid . Here we can see that the Right Split Container * Created above has been used as a parent .
    CREATE OBJECT g_grid2
    EXPORTING
    i_parent = g_cont2 .
    The method of Grid Control Object is used to display the Data.
    CALL METHOD g_grid1->set_table_for_first_display
    EXPORTING
    i_structure_name = 'MARA'
    CHANGING
    it_outtab = i_mara[] .
    The method of Grid Control Object is used to display the Data.
    CALL METHOD g_grid2->set_table_for_first_display
    EXPORTING
    i_structure_name = 'KNA1'
    CHANGING
    it_outtab = i_kna1[] .
    Regards
    Hari

  • How to import user defined class in UIX page?

    Does anyone know how to import user defined class in UIX page so that the class can be called in the javascript in the UIX ?
    Thks & Rgds,
    Benny

    what you are referring to is not javascript.
    it is JSP scriptlets. These are very different.
    In order to keep a strict separation between View and Controller, it is not possible to run arbitrary java code from within your UIX code.
    However, you can run java code from within a UIX event handler; see:
    http://otn.oracle.com/jdeveloper/help/topic?inOHW=true&linkHelp=false&file=jar%3Afile%3A/u01/app/oracle/product/IAS904/j2ee/OC4J_ohw/applications/jdeveloper904/jdeveloper/helpsets/jdeveloper/uixhelp.jar!/uixdevguide/introducingbaja.html
    event handler code is run before the page is rendered.

  • How to put a user defined class in Web dynpro

    How and where can we create some user defined classes?
    For example i wanted to create some utility classs for my project. Under what folder should i create this?

    Please create the .java files under src folder of the project
    Go to PackageExplorer->expand the project->select src/packages and create the package under this and create java file.
    Regards, Anilkumar

  • How to make Shape3D object translucent

    Hi,
    How to make Shape3D object (like Box, Cylinder) translucent? I tried the below option but the box is not becoming translucent at all.
    final PhongMaterial redMaterial = new PhongMaterial();
              redMaterial.setSpecularColor(Color.rgb(10, 255, 15, opacity));
              redMaterial.setDiffuseColor(Color.rgb(10, 255, 15, opacity));
    final Box box = new Box(width,height,depth);
    box.setMaterial(redMaterial);
    When opacity is 1, the color of the box will be Green, when it is 0 the color becomes black.
    Is there any way the box can be made translucent?

    There is at least one unresolved issue concerning PhongMaterial's transparency: RT-28874.
    I'm neither able to get it working properly. My red Sphere also fades to black while varying the opacity value from 1.0 to 0.0.
    August

Maybe you are looking for

  • Multiple Plants sharing 1 shippinh point

    Hi Gurus, I have a requirement that multple plants of different company codes needs to Share 1 shipping point( same address) Actually these 3 plant have 3 PL ware house, so these will have only 1 shipping point. What would be the implicaitons if they

  • Not always receiving MMS message notifications

    I haven't received any MMS message notifications from my friends for approx. the last week, and they certainly have been sending them to me. I know this is definitely happening from Sprint and Verizon customers trying to send to me. I have had issues

  • Gmail task list does not pop-out

    After installing 3.6.7 gmail task list does not pop out. When I click the pop-out arrow, the task list opens in another tab, not in another stripped down window like it used to. Any ideas? == URL of affected sites == http://

  • Need Suggestion  to learn BPEL

    Hi Friends Iam totally new to BPEL please help me to learn it and to become Familiar in BPEL My Qusetion ========= 1) In short what is BPEL .why we are using it and what the actual purpose? 2)From were i start learning bpel 3)what technology is neede

  • Migrating SVN Settings to SQL Developer 3.1EA3

    I had SVN set up in SQL Developer 2 and it was working just fine. When I installed SQL Developer 3, I migrated the settings from SQL Developer 2, but the SVN settings did not move over with it. In addition, when I attempt to set up SVN in SQLDev3, it