List of Immutable Classes?

Is there a list of the classes in the standard lib. which are immutable (or claim to be immutable, or are designed to be immutable)?

"need" is probably too strong a word.
Some reflection based code I am writing can be made more efficient if I know that a class is immutable. For my own work I have an Immutable interface (no methods) which tells me what is immutable. Otherwise I check if the object is a String or a BigInteger (both are immutable I think) otherwise I treat it as if it is not-immutable. That is probably sufficient for the type of work I do.
I was also curious to look into the source and see what techniques the gurus are using for immutable creatures.

Similar Messages

  • Function to return a list of sub-class elements

    Hi all
    I'm trying to write a function using templates which takes a list and returns a sub list of a given type.something like shown below:
    static <E, T> List<E> get_specific_elements(Collection<T> elements) { //assumes E extends T
              List<E> specific_elements= new ArrayList<E>();
              for (T element : elements)
    line 4:               if (element instanceof E)
                        specific_elements.add((E)element);
              return specific_elements;
         }but it gives me at line 4
    Cannot perform instanceof check against type parameter E. Use instead its erasure Object
          since generic type information will be erased at runtimeso is there a way to fix it or any other alternative to make it work.
    thanks
    Sree
    Edited by: sreecs on Nov 5, 2008 10:03 PM
    Edited by: sreecs on Nov 5, 2008 10:04 PM

    In your code, there is no way for the runtime to know what E is. The solution is to tell it.
    static <E extends T, T> List<E> get_specific_elements(Class<E> subtype, Collection<T> elements) {
        List<E> specificElements= new ArrayList<E>();
        for (T element : elements) {
            if (subtype.isInstance(element)) {
                specificElements.add(subtype.cast(element));
        return specificElements;
    }Bruce

  • [svn:bz-4.0.0_fixes] 20651: Some MBean tests needed flex.management. jmx stuff in the allow classes list for the class deserialization validator so adding it in on BlazeDS 4 .0.0_fixes.

    Revision: 20651
    Revision: 20651
    Author:   [email protected]
    Date:     2011-03-07 12:21:11 -0800 (Mon, 07 Mar 2011)
    Log Message:
    Some MBean tests needed flex.management.jmx stuff in the allow classes list for the class deserialization validator so adding it in on BlazeDS 4.0.0_fixes.
    Modified Paths:
        blazeds/branches/4.0.0_fixes/qa/apps/qa-regress/WEB-INF/flex/services-config.mods.validat ors.xml

    Thank you very much!
    I cant believe this little comment has been so helpful!
    But yes it is:
    I explain, despite my efforts to find, googled it, forums, faqs, etc...
    no where it mentionned the manifest.fm file is... INSIDE the .jar!
    Your comment "a zip" made me attempt to open it with winrar, and I found a manifest.fm file inside!
    So far I was editing the one at the "source" of my project and rebuilding it with netbeans.
    I am going to try that now.
    Actually.... :( no its mentionning my main class!
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.0
    Created-By: 10.0-b19 (Sun Microsystems Inc.)
    Main-class: courseworkjava3d.Simple3D
    Class-Path:
    X-COMMENT: Main-Class will be added automatically by buildWell I have no problems uploading you the .jar, it is for a coursework it is not a private project or whatever:
    http://www.uploading.com/files/CM2LKWYU/BetaCourseworkJava3d_Final.jar.html
    Oh and I felt on your comment "dont ask us" as if I was suppose to know... i'm a beginner, I did not know that! And I tried to give you so many infos so you dont lose your time if you want to help, especially as after my own research I found many, many results for this "main class" and I tried a few solutions!
    Edited by: CupofTea on Apr 13, 2008 3:28 AM

  • [svn:bz-trunk] 20650: Some MBean tests needed flex.management. jmx stuff in the allow classes list for the class deserialization validator so adding it in on BlazeDS trunk .

    Revision: 20650
    Revision: 20650
    Author:   [email protected]
    Date:     2011-03-07 12:20:03 -0800 (Mon, 07 Mar 2011)
    Log Message:
    Some MBean tests needed flex.management.jmx stuff in the allow classes list for the class deserialization validator so adding it in on BlazeDS trunk.
    Modified Paths:
        blazeds/trunk/qa/apps/qa-regress/WEB-INF/flex/services-config.mods.validators.xml

    Thank you very much!
    I cant believe this little comment has been so helpful!
    But yes it is:
    I explain, despite my efforts to find, googled it, forums, faqs, etc...
    no where it mentionned the manifest.fm file is... INSIDE the .jar!
    Your comment "a zip" made me attempt to open it with winrar, and I found a manifest.fm file inside!
    So far I was editing the one at the "source" of my project and rebuilding it with netbeans.
    I am going to try that now.
    Actually.... :( no its mentionning my main class!
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.0
    Created-By: 10.0-b19 (Sun Microsystems Inc.)
    Main-class: courseworkjava3d.Simple3D
    Class-Path:
    X-COMMENT: Main-Class will be added automatically by buildWell I have no problems uploading you the .jar, it is for a coursework it is not a private project or whatever:
    http://www.uploading.com/files/CM2LKWYU/BetaCourseworkJava3d_Final.jar.html
    Oh and I felt on your comment "dont ask us" as if I was suppose to know... i'm a beginner, I did not know that! And I tried to give you so many infos so you dont lose your time if you want to help, especially as after my own research I found many, many results for this "main class" and I tried a few solutions!
    Edited by: CupofTea on Apr 13, 2008 3:28 AM

  • Accessing an Array List from another class

    Hi, I was a member on here before, but I forgot my password and my security question is wrong.
    My question is how do I access a private arraylist from a different class in the same package?
    What I am trying to do is the following (hard to explain).
    Make a picking client for a shop, so that when an order is recieved, the picker can click on the orders button, and view all of the current orders that have not been completed. This Pick client has its own user interface, in a seperate class from where the BoughtList array is created, in the cashier client. The boughtlist is created when the cashier puts in the product number into the cashier client and clicks buy. I seem to be having trouble accessing the list from another class. Once the order is completed the cashier clicks bought and the list is reset. There is another class in a different pagage that processes some of the functions of the order, eg newOrder().
    Yes it is for Uni so I dont need / want the full answers, jist something to get started. Also please dont flame me, I have done many other parts of this project, just having trouble getting started on this one.
    Here is the code for the cashier client. The code for the Pick client is almost the same, I just need to make the code that displays the orders.
    package Clients;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.NumberFormat;
    import java.util.Locale;
    import Catalogue.*;
    import DBAccess.*;
    import Processing.*;
    import Middle.*;
    class CashierGUI 
      class STATE                             // Cashier states
        public static final int PROCESS  = 0;
        public static final int CHECKED  = 1;
      class NAME                             // Names of buttons
        public static final String CHECK  = "Check";
        public static final String BUY    = "Buy";
        public static final String CANCEL = "Cancel";
        public static final String BOUGHT = "Bought";
      private static final int H = 300;       // Height of window pixels
      private static final int W = 400;       // Width  of window pixels
      private JLabel      theAction  = new JLabel();
      private JTextField  theInput   = new JTextField();
      private JTextArea   theOutput  = new JTextArea();
      private JScrollPane theSP      = new JScrollPane();
      private JButton     theBtCheck = new JButton( NAME.CHECK );
      private JButton     theBtBuy   = new JButton( NAME.BUY );
      private JButton     theBtCancel= new JButton( NAME.CANCEL );
      private JButton     theBtBought= new JButton( NAME.BOUGHT );
      private int         theState   = STATE.PROCESS;   // Current state
      private Product     theProduct = null;            // Current product
      private BoughtList  theBought  = null;            // Bought items
      private Transaction     theCB        = new Transaction();
      private StockReadWriter theStock     = null;
      private OrderProcessing theOrder     = null;
      private NumberFormat theMoney  =
              NumberFormat.getCurrencyInstance( Locale.UK );
      public CashierGUI(  RootPaneContainer rpc, MiddleFactory mf  )
        try                                             //
          theStock = mf.getNewStockReadWriter();        // DataBase access
          theOrder = mf.getNewOrderProcessing();        // Process order
        } catch ( Exception e )
          System.out.println("Exception: " + e.getMessage() );
        Container cp         = rpc.getContentPane();    // Content Pane
        Container rootWindow = (Container) rpc;         // Root Window
        cp.setLayout(null);                             // No layout manager
        rootWindow.setSize( W, H );                     // Size of Window
        Font f = new Font("Monospaced",Font.PLAIN,12);  // Font f is
        theBtCheck.setBounds( 16, 25+60*0, 80, 40 );    // Check Button
        theBtCheck.addActionListener( theCB );          // Listener
        cp.add( theBtCheck );                           //  Add to canvas
        theBtBuy.setBounds( 16, 25+60*1, 80, 40 );      // Buy button
        theBtBuy.addActionListener( theCB );            //  Listener
        cp.add( theBtBuy );                             //  Add to canvas
        theBtCancel.setBounds( 16, 25+60*2, 80, 40 );   // Cancel Button
        theBtCancel.addActionListener( theCB );         //  Listener
        cp.add( theBtCancel );                          //  Add to canvas
        theBtBought.setBounds( 16, 25+60*3, 80, 40 );   // Clear Button
        theBtBought.addActionListener( theCB );         //  Listener
        cp.add( theBtBought );                          //  Add to canvas
        theAction.setBounds( 110, 25 , 270, 20 );       // Message area
        theAction.setText( "" );                        // Blank
        cp.add( theAction );                            //  Add to canvas
        theInput.setBounds( 110, 50, 270, 40 );         // Input Area
        theInput.setText("");                           // Blank
        cp.add( theInput );                             //  Add to canvas
        theSP.setBounds( 110, 100, 270, 160 );          // Scrolling pane
        theOutput.setText( "" );                        //  Blank
        theOutput.setFont( f );                         //  Uses font 
        cp.add( theSP );                                //  Add to canvas
        theSP.getViewport().add( theOutput );           //  In TextArea
        rootWindow.setVisible( true );                  // Make visible
      class Transaction implements ActionListener       // Listener
        public void actionPerformed( ActionEvent ae )   // Interaction
          if ( theStock == null )
            theAction.setText("No conection");
            return;                                     // No connection
          String actionIs = ae.getActionCommand();      // Button
          try
            if ( theBought == null )
              int on    = theOrder.uniqueNumber();      // Unique order no.
              theBought = new BoughtList( on );         //  Bought list
            if ( actionIs.equals( NAME.CHECK ) )        // Button CHECK
              theState  = STATE.PROCESS;                // State process
              String pn  = theInput.getText().trim();   // Product no.
              int    amount  = 1;                       //  & quantity
              if ( theStock.exists( pn ) )              // Stock Exists?
              {                                         // T
                Product pr = theStock.getDetails(pn);   //  Get details
                if ( pr.getQuantity() >= amount )       //  In stock?
                {                                       //  T
                  theAction.setText(                    //   Display
                    pr.getDescription() + " : " +       //    description
                    theMoney.format(pr.getPrice()) +    //    price
                    " (" + pr.getQuantity() + ")"       //    quantity
                  );                                    //   of product
                  theProduct = pr;                      //   Remember prod.
                  theProduct.setQuantity( amount );     //    & quantity
                  theState = STATE.CHECKED;             //   OK await BUY
                } else {                                //  F
                  theAction.setText(                    //   Not in Stock
                    pr.getDescription() +" not in stock"
              } else {                                  // F Stock exists
                theAction.setText(                      //  Unknown
                  "Unknown product number " + pn        //  product no.
            if ( actionIs.equals( NAME.BUY ) )          // Button BUY
              if ( theState != STATE.CHECKED )          // Not checked
              {                                         //  with customer
                theAction.setText("Check if OK with customer first");
                return;
              boolean stockBought =                      // Buy
                theStock.buyStock(                       //  however
                  theProduct.getProductNo(),             //  may fail             
                  theProduct.getQuantity() );            //
              if ( stockBought )                         // Stock bought
              {                                          // T
                theBought.add( theProduct );             //  Add to bought
                theOutput.setText( "" );                 //  clear
                theOutput.append( theBought.details());  //  Display
                theAction.setText("Purchased " +         //    details
                           theProduct.getDescription()); //
    //          theInput.setText( "" );
              } else {                                   // F
                theAction.setText("!!! Not in stock");   //  Now no stock
              theState = STATE.PROCESS;                  // All Done
            if ( actionIs.equals( NAME.CANCEL ) )        // Button CANCEL
              if ( theBought.number() >= 1 )             // item to cancel
              {                                          // T
                Product dt =  theBought.remove();        //  Remove from list
                theStock.addStock( dt.getProductNo(),    //  Re-stock
                                   dt.getQuantity()  );  //   as not sold
                theAction.setText("");                   //
                theOutput.setText(theBought.details());  //  display sales
              } else {                                   // F
                theOutput.setText( "" );                 //  Clear
              theState = STATE.PROCESS;
            if ( actionIs.equals( NAME.BOUGHT ) )        // Button Bought
              if ( theBought.number() >= 1 )             // items > 1
              {                                          // T
                theOrder.newOrder( theBought );          //  Process order
                theBought = null;                        //  reset
              theOutput.setText( "" );                   // Clear
              theInput.setText( "" );                    //
              theAction.setText( "Next customer" );      // New Customer
              theState = STATE.PROCESS;                  // All Done
            theInput.requestFocus();                     // theInput has Focus
          catch ( StockException e )                     // Error
          {                                              //  Of course
            theOutput.append( "Fail Stock access:" +     //   Should not
                                e.getMessage() + "\n" ); //  happen
          catch ( OrderException e )                     // Error
          {                                              //  Of course
            theOutput.append( "Fail Order process:" +    //   Should not
                                e.getMessage() + "\n" ); //  happen
    }

    (disclaimer: I did not read through your Swing code, as I find that painful)
    My question is how do I access a private arraylist from a different class in the same
    package?Provide a public accessor method (getMyPrivateArrayList())

  • What is the address for list of htmlb classes...?

    Hi, does anyone know where I can find the list of CSS classes that htmlB uses?  For example, when I view source for htmlB button, I see that the css class '<b>urBtnStd</b>' is used, where can I find a list of these classes?
    Thanks so much,
    Baggett.

    package com.mycompany.test;
    import com.sapportals.portal.prt.component.*;
    public class CSSTest extends AbstractPortalComponent
        public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
          response.write("<html><head><title>CSS test</title></head><body class = 'gSAPBody'>");
          response.write("<B class='gSAPB'>Using SAP style sheets</b>");
          response.write("</body></html>");
    To use CSS classes gSAPB, gSAPBody, gSAPInputText, gSAPInputButton etc., It is not required to add any stylesheets explicitly.
    From the broswer HTML code, it can be observed that depending on the theme, Browser(IE, NetScape Navigator) and version respective style sheets are included.
    If you search in ur file system for the *.css file with the string 'gSAPBody', you can find lot files based on theme and browser.
    I don't know where we can find the documentation for these classes - gSAPBody etc. I found this technique in the book "SAP Enterprise Portal" by SAP Press.
    Hope this helps.
    ~kranthi

  • How to list all available classes?

    Hi *,
    Is there a possibility to list all the classes available to the JVM? I would like to have a list like this:
    java.lang.String
    java.util.Vector
    and so on.
    koem

    Good joke, but that is not what I meant :)
    I would like to get all the class-names at runtime. Because this list depends on the classpath it can be different with every invocation of the my program.

  • Immutable class

    Can anyone tell me how we can create immutable class?

    Prateek wrote:
    Can anyone tell me how we can create immutable class?Do you have clear idea about the immutable class? String class is an immutable class. Look at the [url http://www.docjar.com/html/api/java/lang/String.java.html]String class for example and try by your own, and if you get struck then come back with your works.

  • How To write Immutable Class

    Hi All
    can We write Immutable Class. If yes Then How.
    In my View It can be through final Keyword.

    An immutable class is simply a class whose internal
    data can't be changed once it's created. All fields
    will be declared private and no externally accessible
    methods will change them. That's all that's required.
    It's probably a good idea to declare the fields in
    the class as final, but it's not essential.
    Instead of mutator methods you typically have methods
    that create a new instance with some part of the data
    changed.Note that "final" has two meanings:
    1) a field must be set inside the constructor and nowhere else
    2) a method / class cannot be inherited
    You MUST forbid inheritance, or a subclass might override the methods and reenable mutability. This would have really nasty sideeffects.

  • Our own immutable class

    Hi,
    i have one requirement like ,need to develope my own immutable class like String class.if any one have sample code please post .
    Thanks,
    Anil.

    Make your class final. If you class has instance variables, make them private and final. Each instance variable's type itself should be immutable. If you do have mutable instance variables, then ensure when you write the class that you do not provide methods that mutate their values.
    - Saish

  • List of Object Classes

    Hello,
    Does anyone know the relationship between 'Object Class' and R/3 Document Types... My question is how one determines, for example, that VERKBELEG pertains to Sales Document Changes; and LIEFERUNG is for ... and so on...? Where in R/3 (or in Help Documentation)is this defined?
    This relationship is helpful in searching thru the massive table CDHDR.
    The table TCDOB <b>only</b> lists all of Object Classes.
    Thanks in advance.
    Naved

    Hello Naved,
    I do not think that the Object List will be linked to a document type. At best, we can expect to find the purpose of an Object Class, as intended (not "defined") by SAP.
    If you go to the table TCDOBT (text table of TCDOB), you will find the descriptions of each of the change document classes, as given by SAP. For Example,
    LIEFERUNG          Delivery
    LIBE               Change document vendor evaluation
    VERKBELEG          Sales document
    PRCTR              Profit center master record
    PRODCAT            Product catalog
    and so on.
    Also, there's a Function Module that you might find to be useful - CDNAMES_GET.
    If you want to find out the Object Class for a particular scenario, the best way that I can think of is to go to the table TCDOBT and search with the help of the OBTEXT field.
    Hope this information was helpful. All the best.
    Regards,
    Anand Mandalika.

  • Can't add to display list from a class

    in my Main.as file, this works as expected:
    var t:TextField = new TextField();
    t.text = "hello in main";
    addChild(t);
    However, when I create an instance of a class, and I have
    that same code in the constructor of that class, the text doesn't
    show up. I am creating the text field variable at the class level,
    not the contstructor level, so I think the variable should still
    hang around.
    Do I have to get an instance of the stage, or something?
    thanks

    I don't know anything about your application but there are at
    least two ways to add an instance from within other class:
    1. stage.addChild(t)
    2. Instantiate the class that creates text field --> add
    this instance to the display list of where you instantiated it
    (given that you class that creates the text field is a display ob
    ject too).
    Sorry, I cannot be more specific unless I know more about
    your architecture and logic.

  • Sorting a list of different class objects

    Hi All ,
    How to sort a List a.which contains objects of different Classes, b. objects of same class . Is it possible to sort these by implementing Comparable interface .
    Thanks ,
    Rajesh Reddy

    rajeshreddyk wrote:
    Hi All ,
    How to sort a List a.which contains objects of different Classes, b. objects of same class . Is it possible to sort these by implementing Comparable interface .Well, if objects of different classes are kept in the same List and you want to sort them together they at least have that in common. They're Comparable-able. -:) To manifest that the different classes could all implement a Comparableable interface (or maybe Intercomparable would be a better choise of name.)

  • How to craete a list of a class

    can any one tell me how to create a list of a class

    Senmku wrote:
    can any one tell me how to create a list of a classWhat exactly do you mean by that? Convert a class into a list, or create a list holding instances of a certain class?

  • Problem adding to the display list from a class

    If I try to convert as3 in an mxml file into a class file and
    create an instance of the class, I am unable to add the instance to
    the display list. The original mxml file is at the bottom of the
    page. The modified mxml file and its associated class are below.
    The problem is that I cannot use addChild(myComponent); So how to I
    add the UIComponent to the Display list?
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute" creationComplete="init()">
    <mx:Script>
    <![CDATA[
    import LoadSwf
    private var myLoader:LoadSwf
    public function init():void{
    myLoader=new LoadSwf()
    ]]>
    </mx:Script>
    </mx:Application>
    Class:
    package{
    import flash.display.MovieClip;
    import com.adobe.viewsource.ViewSource;
    import flash.events.Event
    import mx.core.UIComponent
    import flash.display.Loader
    import flash.events.TimerEvent;
    import flash.events.StatusEvent
    import flash.net.LocalConnection
    import flash.net.URLRequest
    import flash.net.URLVariables
    import flash.utils.Timer;
    public class LoadSwf{
    private var request:URLRequest
    private var loader:Loader = new Loader();
    private var conn:LocalConnection = new LocalConnection();
    private var myComponent:UIComponent=new UIComponent();
    private var swfTimer:Timer;
    private var myParameters:URLVariables ;
    public function LoadSwf(){
    request= new URLRequest("Login.swf");
    myParameters= new URLVariables()
    myParameters.loginID = "101";
    myComponent.addChild(loader);
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
    finishedLoading);
    loader.load(request);
    private function finishedLoading(e:Event):void{
    //PROBLEM IN THE FOLLOWING LINE!!!!!!!
    addChild(myComponent);
    swfTimer = new Timer(10);
    swfTimer.addEventListener(TimerEvent.TIMER,sendData);
    swfTimer.start();
    private function sendData(e:Event):void{
    conn.addEventListener(StatusEvent.STATUS, onStatus);
    conn.send("myConnection", "lcHandler",
    myParameters.loginID);
    private function onStatus(event:StatusEvent):void {
    if (event.level=="status") {
    trace("LocalConnection connected");
    swfTimer.stop();
    }else if (event.level=="error"){
    trace("FAILED to connect")
    }

    "SiHoop" <[email protected]> wrote in
    message
    news:[email protected]...
    > If I try to convert as3 in an mxml file into a class
    file and create an
    > instance of the class, I am unable to add the instance
    to the display
    > list. The
    > original mxml file is at the bottom of the page. The
    modified mxml file
    > and its
    > associated class are below. The problem is that I cannot
    use
    > addChild(myComponent); So how to I add the UIComponent
    to the Display
    > list?
    >
    > <?xml version="1.0" encoding="utf-8"?>
    > <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    > layout="absolute"
    > creationComplete="init()">
    > <mx:Script>
    > <![CDATA[
    > import LoadSwf
    > private var myLoader:LoadSwf
    > public function init():void{
    > myLoader=new LoadSwf()
    > }
    > ]]>
    > </mx:Script>
    > </mx:Application>
    > Class:
    > package{
    > import flash.display.MovieClip;
    > import com.adobe.viewsource.ViewSource;
    > import flash.events.Event
    > import mx.core.UIComponent
    > import flash.display.Loader
    > import flash.events.TimerEvent;
    > import flash.events.StatusEvent
    > import flash.net.LocalConnection
    > import flash.net.URLRequest
    > import flash.net.URLVariables
    > import flash.utils.Timer;
    > public class LoadSwf{
    > private var request:URLRequest
    > private var loader:Loader = new Loader();
    > private var conn:LocalConnection = new
    LocalConnection();
    > private var myComponent:UIComponent=new UIComponent();
    > private var swfTimer:Timer;
    > private var myParameters:URLVariables ;
    > public function LoadSwf(){
    > request= new URLRequest("Login.swf");
    > myParameters= new URLVariables()
    > myParameters.loginID = "101";
    > myComponent.addChild(loader);
    >
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
    > finishedLoading);
    > loader.load(request);
    > }
    > private function finishedLoading(e:Event):void{
    > //PROBLEM IN THE FOLLOWING LINE!!!!!!!
    > addChild(myComponent);
    You didn't add this component to the Application, so I
    wouldn't expect to
    see anything you add in this component in the Application.
    HTH;
    Amy

Maybe you are looking for