Question about declaring type as interface

Hi
I am trying to get my head around declaring an object as the interface type (I think this is right correct me if I am wrong). Ok so I understand if I declare my object reference as the interface I will only get the methods of the interface defined in the objects class..? ie
List myList = new ArrayList();I think any method particular to ArrayList will not be there. But I dont actually understand wha is happening here, I have a ref to a List but the object is actually an ArrayList?
So if I passed ths list to a session object and got it out I could cast it back to the interface. I dont understand why or what is happening here.
I hope someone understands my question enough that they can help me out, this has been nugging me for a while.
Thanks

I am trying to get my head around declaring an object
as the interface type (I think this is right correct
me if I am wrong). Ok so I understand if I declare my
object reference as the interface I will only get the
methods of the interface defined in the objects
class..? ie
List myList = new ArrayList();I think any method particular to ArrayList will not
be there. If you use myList without casting, then, yes, only List's methods will be available, because all the compiler knows is that it's a reference to a List. It doesn't know that at runtime it will point to an ArrayList object.
You could cast myList to ArrayList to get ArrayList-specific things (if there are any), but a) if you're not careful, you can end up with a ClassCastException at runtime (you won't here, but in general you can) and b) if you're going to do that, you have to question why you declared it as a List in the first place. There are cases where casting is appropriate, but you have to be careful.
But I dont actually understand wha is
happening here, I have a ref to a List but the object
is actually an ArrayList?Yes.
So if I passed ths list to a session object and got
it out I could cast it back to the interface. I dont
understand why or what is happening here.You could cast it to anything that the object actually is, that is, any of its superclasses and superinterfaces. If it's an ArrayList, you could cast it to any of the following: ArrayList, AbstractList, AbstractCollection, Object, Serializable, Cloneable, Iterable, Collection, List, RandomAccess.

Similar Messages

  • A question about item "type and release" of  source system creation

    Hello expert,
    I have a question about item "type and release" of  source system creation.
    As we know,when we create a web servie source system,there will display a pop-up which includes three items as "logical system","source system"and "type and release".
    About the item "type and release",when we push "F4" button,there will be three default selections as below:
    "ORA 115     Oracle Applications 11i
    TLF 205     Tealeaf 2.05B
    XPD 020     SAP xPD".
    Who can tell me when and how should I use the three selections.
    And also I attempted to input the item by some optional letters except the default three selections and it seems that I can input it freely.
    Thank you and Best Regards,
    Maggie

    Hello DMK,
    Thank you very much for your answer.It is very helpful for me.
    Can I ask you further about it?
    I got that it is a semantic description item.
    You said the default selections are set by our basis people.Would you like to tell me how should we creat a new value except the default ones for item "type and release"?Only by inputing the value in the item directly?But you see we canot see the new value item we created by ourself when we push "F4" button next time ,is that ok?Or do we have to ask basis people to define one new value item just like the default seletions before we use it.
    Also if possible would you like to describe detail about "This becomes important when you are troubleshooting certain issues especially when RFC connection problems."
    Thank you and Best Regards,
    Maggie
    Message was edited by: Maggie

  • Question about histogram types

    Hi there,
    I have question about HISTOGRAM column in ALL_TAB_COLUMNS.
    There are 3 different histogram modes in all_tab-columns.:
    NONE, FREQUENCY , and HEIGHT BALANCED .
    Has anyone knows about these options in detail and how can I change between
    these?
    Thanks.

    And Wolfgang Breitling's papers are always the best resources about histogram.
    http://www.centrexcc.com/papers.html

  • Question about throws exception in interface and realized class

    Hi,all
    If I define a method In the interface like that-
    public void Execute() throws NumberFormatException; In the realized class, I can define this method like that-
    public void Execute() throws RuntimeException{
            System.out.println("test");       
    }This is a right realization. But if I manage it to throws Exception or to throws Throwable in the class it leads a error. Why add this restrict only to Exception? What is the purpose of this way?
    Greetings and thanks,
    Jason

    When you say "throws NumberFormatException" you are really saying:
    When using classes implementing this interface, you have to be prepared to deal with them throwing a NumberFormatException. Other exceptions won't happen.
    When you come to implement it, it might not be possible for it to throw a NumberFormatException, so there's no reason why you should have to lie about that. Code handling it directly will be fine (it doesn't throw a NFE) and code handling it via the interface will be fine (it will handle NFEs, they just don't happen).
    If your concrete implementation throws other sorts of exception, such as Exception or IOException, and so on, it's incompatible with code that's manipulating the interface. The interface says "NFEs might get thrown, nothing else will." while your implementation says "IOExceptions might get thrown".
    So that explains why you can't use arbitrary exceptions. The special case is RuntimeException. RuntimeExceptions don't have to be caught, and it's expected that they can happen at any time - so there's no point trying to catch and handle them as a general case.
    The classic example of a RuntimeException is a NullPointerException. You don't need to declare your method as throwing a NullPointerException even though it might get thrown. And you don't have to add NullPointerException to the throws part of the interface definition, because you already know that the concrete implementation could throw a NPE at any time.
    Hope that helps (a little).
    I'd recommend reading the API documentation on RuntimeException and Exception to get a clearer insight into this.
    Dave.

  • Theorical question about declaration/definition in java

    Hi, we know the difference between declaration and definition:
    -declaration: no memory is allocated.
    -definition: memory is allocated.
    In C/C++ if we want to define a variable we can make
    int x;or
    int x = 5; (we assign a value too)
    while, if we just want to declare we can make
    extern int x;Is there a way in java to simply declare a variable? According to me just arrays can be declared with
    String[] arrayString;while istructions like
    String myString;are definition as they allocate at least a String reference on the stack...am I wrong?

    Squall867 wrote:
    Hi, we know the difference between declaration and definition:
    -declaration: no memory is allocated.
    -definition: memory is allocated.That's not the definition I learned, back when dinosaurs roamed the earth, men lived in caves and used pterodactyls for airplanes, and computers were made of rocks.
    Is there a way in java to simply declare a variable? According to me just arrays can be declared withThis is a pretty meaningless question.
    In Java, whenever you declare/define a variable (there is no distinction), space is allocated for that variable. It's at least 1 byte for a byte or boolean, at least 2 bytes for a char or a short, at least 4 bytes for an int, float, or reference, and at least 8 bytes for a double or long. A given JVM implementation may actually use more bytes for any given type for word-alignment performance optimization.
    Is there a way in java to simply declare a variable? According to me just arrays can be declared with
    String[] arrayString;
    This declares a reference variable of type reference to array of String. It will occupy at least 4 bytes.
    while istructions like
    String myString;are definition as they allocate at least a String reference on the stack...am I wrong?This declares a reference variable of type reference to String. It will occupy at least 4 bytes.
    Note that an array reference variable is no different than any other reference variable.
    Also note that for any variable, whether it lives on the stack or on the heap depends only on whether it's a member variable or a local variable. If objects are allowed to be created on the stack in future versions of Java, that distinction will get slightly more complex.

  • Question about insertitem in component interface

    Hi:
    I'm using component interface in my work and face a question. When I use InsertItem function in peoplecode, I'm confused about its relationship with ActiveRowCount property of Row class. I need to check the data inserted in the record, so I put logic in component fieldchange event, uses ActiveRowCount to loop in the record to check every one row .
    In the PIA, if we insert one row(by click add button) for some record, ActiveRowCount seems include the row you just insert even if you have not click save button. But when I use InsertItem and triggered a FieldChange event, ActiveRowCount in this event seems not include the new row inserted by InsertItem function. It is quite different from inserting in PIA. I'm not sure whether I uses InsertItem in a wrong way or it is just a mechanism that component interface implemented to exclude InsertItem inserted row in ActiveRowCount ? Hope someone can help me. Thanks a lot.

    That doesn't make sense to me. Regardless of whether you are going through the PIA or through a Component Interface, your ActiveRowCount should increment the same.
    Is it possible that maybe your CI code is inserting into a different RowSet than what you are doing online through the PIA?
    I don't know if this terminology helps --
    Online via PIA | Component Interface
    RowSet = Collection
    ActiveRowCount = Count
    Row = Collection
    Field = Property
    Also be sure that your FieldChange is getting triggered after you insert the row. I am not sure how you are viewing the ActiveRowcount. If it is a message, I would assume that shows up in the message collection. The message collection will just queue the messages and you can check them at the end. So, what could happen is that your field change is getting triggered first and the message gets added to the collection. Then, you could insert the row. Then, you could check messages and see the count from before the row insert yet it looks like after the row insert. You might consider printing all your messages from the collection right before the row insert and deleting any pending messages.
    If you would like to post some of your code, maybe we can help more. Hope that much helps.

  • Question about mapping a JAVA Interface with Flex

    I am using Granite Data Services (Java backend) with my Flex
    client.
    The Java server has an Interface called
    public interface IService {String getServiceName();}
    The flex client makes a remote service call on the server
    POJO which returns any implementation of the specified interface.
    On the flex side I have an interface
    [Bindable]
    [RemoteClass(alias="com.*****.proxy.pojo.IService")]
    public interface IService{function getServiceName():String;}
    As shown i am binding it to the server interface.
    From the client I make a call to the server and handle the
    result as shown below
    var serviceInstance:IService =
    (remoteO.testInterface.lastResult as IService);
    Alert.show("Service Name :
    "+serviceInstance.getServiceName());
    The call reaches the server and the remote method is being
    called however the Alert is not working.
    Please Help !!

    //Start other thread closeT
    System.exit(0)
    //code for thread closeT
    //wait 10 s
    Runtime.getRuntime().halt()
    Gil

  • Very simple question about declaring variables

    if a create a new ' int ' as in the code below :
    static int counter;
    does the value of counter automatically default to ' 0 ' ?
    Does this also apply if i declare the var to be public, protected etc ( but not final )
    thanks

    Most languages will initialise an int to 0 if no value is specified but it is dangerous to rely on this as it is not always the case. It is therefore recommended as good practice that you always initialise your own variables to ensure they start with the value you wish and not something unexpected.
    Mark.

  • Question about Intel 82801FBM LPC Interface Controller in a Tecra A3X

    I have had to replace the HDD in a A3X. XP pro sp2 loaded fine and all's well but the device mngr is reporting this Intel 82801FBM LPC Interface Controller as an Unknown Device.
    The Intel Chipset ID Utility identifies this as a component of the Chipset 82915GM/GMS/910 GML
    I have run the Intel software update utility several times with no joy.
    I can find reference's to this driver but cannot find a download for it.
    Like I said the laptop seems to running fine except for this Unknown Device.
    Any suggestions greatly appreciated

    Hi,
    "Dont go to the seas when you can fish from the coast" - quoted the user from another forum which wrote this solution for your problem:
    1)Go into device manager
    2) Right click 82801
    3) Update driver
    4) No, not this time -> next
    5) Install from a specifin location -> next
    6) Dont search I will choose... -> next
    7) From the left box choose Intel and from the right scroll down until you meet this strange 82801FMB.... -> next
    Thats it!
    Thanks to google. :)
    Greets

  • Question about declare and create an object

    There are 2 classes and one is subclass of another like below:
    class A { }
    class B extends A {
    1. A x = new B();  // x is a *reference variable* of class A and it points to( refer to) an *object* of class B
    2. B x = new A();  // x is a *reference variable* of class B and it points to( refer to) an *object* of class A
    }       The first one is correct one but the second. I do not have a good explanation for that. The only thing I just know is just because B extends A. Im not convinced myself. Pls help, thanks
    Edited by: newbie on Oct 25, 2010 11:03 PM
    Edited by: newbie on Oct 25, 2010 11:26 PM

    newbie wrote:
    There are 2 classes and one is subclass of another like below:
    class A { }
    class B extends A {
    1. A x = new B();  // x is a *reference variable* of class A and it points to( refer to) an *object* of class B
    2. B x = new A();  // x is a *reference variable* of class B and it points to( refer to) an *object* of class A
    }       The first one is correct one but the second. I do not have a good explanation for that. The only thing I just know is just because B extends A. Im not convinced myself. Pls help, thanksB extends A means that every B is-an A. That's part of what inheritance means. The main part, IMHO. When you do new B(), you are creating a B object. That B is also an A. Therefore, it is legal to refer to it with a reference variable of type A.
    A a; // this says that variable "a" must point to an A object.
    a = new B(); // this is legal because every B is an A, so, by pointing to a B object, it is in fact pointing to an AHowever, not all A objects are also B objects
    B b; // this says that varaible "b" must point to a B object
    b = new A(); // That A is NOT a B object.If you say "hand me a fruit", and someone hands you a pear, and apple, or a banana, he has handed you a fruit.
    But if you say "hand me a banana", not just any fruit will do.
    Edited by: jverd on Oct 26, 2010 9:55 AM

  • Question about storage type 902

    Hello Everybody!
    I´m implementing SAP WM and I have a doubt and is the next one:
    When I do a material movement, system returns an error if the material is not create in the destiny storage type.
    On the other hand, I create a purchase order and when I make the good entrance, the system stocks the material in the storage type 902 even the material is not create in this storage type.
    Why is the reason for this? Is not necessary to create the materials in the standar storage type like 902?
    Thank you very much for your help!

    Hello Javier
    You are right when it comes to goods receipt or goods issue. All the 9** series storage types are interim storage types which are fictitious. You only have to create 1 bin for each interim storage types. When you create the material master maintain the WM views only for the warehouse number and the other storage types  that you use where all the bins are located. For storage types 902 the PO/inbound delivery number and for 916 outbound delivery number will be displayed as the bin numbers which are dynamic bins that gets deleted automatically once you complete the movements.
    Thanks
    Anandha

  • Question about wait type NETWORK_IO

    From the articles below, we know the NETWORK_IO composed by network transmission + Client application dealing with the rows.
    That's suppose the NETWORK_IO  is 100 seconds, so my question is how many seconds spent for network transmission , and how many seconds spent for  Client application ?
    As If I don't know the time spent for the two components respectively, I wouldn't  know if it is a network issue Or Client application issue.
    http://blogs.msdn.com/b/joesack/archive/2009/01/09/troubleshooting-async-network-io-networkio.aspx
    http://mssqlwiki.com/sqlwiki/sql-performance/async_network_io-or-network_io/
    Please click the Mark as Answer button if a post solves your problem!

    As If I don't know the time spent for the two components respectively, I wouldn't  know if it is a network issue Or Client application issue.
    Hi,
    Wait stats are cumulative and the 100 ms would include total waiting time it wont be possible to segregate the time. Its cumulative of time when result set was sent to client and when client gave acknowledgement  that result set is consumed
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
    My Technet Wiki Article
    MVP

  • Question about file type designations

    Hi,
    I use a program called Sound Studio to record meetings that I do. Lately, what's happening now when I download videos emailed by friends, the file extension says .mp4, but when I open them, Sound Studio opens up and I only hear the audio (because audio is all that program does). When I do the get info command, the instructions say open file with Sound Studio, rather than QuickTime.
    Is there some kind of setting somewhere, either in Snow Leopard or in Safari, where I can set that all downloaded video files are to be opened by Quicktime?
    Thanks.

    elgefe wrote:
    Hi,
    I use a program called Sound Studio to record meetings that I do. Lately, what's happening now when I download videos emailed by friends, the file extension says .mp4, but when I open them, Sound Studio opens up and I only hear the audio (because audio is all that program does). When I do the get info command, the instructions say open file with Sound Studio, rather than QuickTime.
    change the default app in that popup from sound studio to anything you want to use like Quicktime player and click 'change all".

  • Technichal question about primative types

    A float is 32-bits but not all are used for storing the number, does anybody know weather they have a set structure or/and in which order the bits are set out?
    I am wondering weather it is possible to bitshift, or use other bit-wise operations for that matter.
    Thanks in advance. Bamkin

    IEEE 754 floating point numbers have the following bit-assignments -- bit 31 sign bit (s)
    bit 31-24 exponent (e)
    bit 23-00 mantissa (m) When the sign bit (s) is zero, the number is positive, otherwise it's negative. The exponent part
    is biased, i.e. the 'real' exponent is interpreted as e-127, so the 'real' exponent has a range
    [-127, 128]. If the exponent (e) equals zero, the mantissa (m) is adjusted to 'm<<1', otherwise
    'm|800000' is used. The latter trick effectively adds one more bit of accuracy to the mantissa.
    If the mantissa (m) equals zero and the exponent (e) equals 0xff, the number is considered
    to be +/- infinity (depending on the sign bit).
    kind regards,
    Jos

  • Question about size of ints in Xcode

    Hello. I have a a few quick questions about declaring and defining variables and about their size and so forth. The book I'm reading at the moment, "Learn C on the Mac", says the following in reference to the difference between declaring and defining a variable:
    A variable declaration is any statement that specifies a variables name and type. The line *int myInt;* certainly does that. A variable definition is a declaration that causes memory to be allocated for the variable. Since the previous statement does cause memory to be allocated for myInt, it does qualify as a definition.
    I always thought a definition of a variable was a statement that assigned a value to a variable. If a basic declaration like "int myInt;" does allocate memory for the variable and therefore is a definition, can anyone give me an example of a declaration that does not allocate memory for the variable and therefore is not a definition?
    The book goes on, a page or so late, to say this:
    Since myInt was declared to be of type int, and since Xcode is currently set to use 4-byte ints, 4 bytes of memory were reserved for myInt. Since we haven't placed a value in those 4 bytes yet, they could contain any value at all. Some compilers place a value of 0 in a newly allocated variable, but others do not. The key is not to depend on a variable being preset to some specific value. If you want a variable to contain a specific value, assign the value to the variable yourself.
    First, I know that an int can be different sizes (either 4 bytes or 8 bytes, I think), but what does this depend on? I thought it depended on the compiler, but the above quote makes it sound like it depends on the IDE, Xcode. Which is it?
    Second, it said that Xcode is currently set to use 4-byte ints. Does this mean that there is a setting that the user can change to make ints a different size (like 8 bytes), or does it mean that the creators of Xcode currently have it set to use 4-byte ints?
    Third, for the part about some compilers giving a newly allocated variable a value of 0, does this apply to Xcode or any of its compilers? I assume not, but I wanted to check.
    Thanks for all the help, and have a great weekend!

    Tron55555 wrote:
    I always thought a definition of a variable was a statement that assigned a value to a variable. If a basic declaration like "int myInt;" does allocate memory for the variable and therefore is a definition, can anyone give me an example of a declaration that does not allocate memory for the variable and therefore is not a definition?
    I always like to think of a "declaration" to be something that makes no changes to the actual code, but just provides visibility so that compilation and/or linking will succeed. The "definition" allocates space.
    You can declare a function to establish it in the namespace for the compiler to find but the linker needs an actual definition somewhere to link against. With a variable, you could also declare a variable as "extern int myvar;". The actual definition "int myvar;" would be somewhere else.
    According to that book, both "extern int myvar;" and "int myvar;" are declarations, but only the latter is a definition. That is a valid way to look at it. Both statements 'delcare' something to the compiler, but on the second one 'define's some actual data.
    First, I know that an int can be different sizes (either 4 bytes or 8 bytes, I think), but what does this depend on? I thought it depended on the compiler, but the above quote makes it sound like it depends on the IDE, Xcode. Which is it?
    An "int" is supposed to be a processor's "native" size and the most efficient data type to use. A compiler may or may not be able to change that, depending on the target and the compiler. If a compiler supports that option and Xcode supports that compiler and that option, then Xcode can control it, via the compiler.
    Second, it said that Xcode is currently set to use 4-byte ints. Does this mean that there is a setting that the user can change to make ints a different size (like 8 bytes), or does it mean that the creators of Xcode currently have it set to use 4-byte ints?
    I think that "setting" is just not specifying any option to explicitly set the size. You can use "-m32" or "-m64" to control this, but I wouldn't recommend it. Let Xcode handle those low-level details.
    Third, for the part about some compilers giving a newly allocated variable a value of 0, does this apply to Xcode or any of its compilers? I assume not, but I wanted to check.
    I don't know for sure. Why would you ask? Are you thinking of including 45 lines of macro declarations 3 levels deep to initialize values based on whether or not a particular compiler/target supports automatic initialization? Xcode current supports GCC 3.3, GCC 4.0, GCC 4.2, LLVM GCC, CLang, and Intel's compiler for building PPC, i386, and x86_64 code in both debug and release, with a large number of optimization options. It doesn't matter what compiler you use or what it's behavior is - initialize your variables in C.

Maybe you are looking for

  • Download still in progress...agent never registers with SDS

    Team, I've installed agents on a number of hosts and successfully patched and upgraded them, and I've recently run into a problem where the agent never seems to complete it's registration with the SDS. The agent error.log shows this: 7381:2008-04-28_

  • Need Printing Help (location to top-left?)

    im able to print out a JFrame, no problem..but the onscreen image and whats printed on paper arent exactly the same 1) Printed is 1.5 - 2X bigger than onscreen (1280x1024 resolution) 2) Printed starts near the middle of the page, not at the top left

  • Atv2 won't move beyond Library heading - but pc does!

    Usual new Appletv, connected to two MacBooks; both show up under 'computers' but selecting them just loads library - repeatedly! Bafflingly, the relevant MacBook /does/ respond to the Appletv remote.... How can I get my music/films to show up on my T

  • EXISTS vs. IN - EXISTS does not work by IN does

    I have a query with 3 subqueries. Values must be in all three subqueries to be returned. My test case is commented out in the query below. When I use the subquery using an in statement /* in the commented section */ the test case does not get returne

  • Problem invoking UCM 11g Web services from ODI 11g

    We have a running UCM 11g instance with its web services (GenericRequest) properly configurated. The wsdl is published in the url http://ucmt:16200/idcws/GenericSoapPort?WSDL and reacheble from any web browser. The service can be easily invoked from