Where and when to use generics?

I'm brushing up on Java 5.0, I'm at 'generics' - I always hated c++ templates and knew they would catch up with me sooner or later...
I have a fairly simple question about where and how to use them, conceptually.
Am I correct in thinking that they are primarily concerned with items contained within a class and passed to a class?
I'm trying to find a useful bit of code to write to practice with them and I've been half tempted to re-write something that uses lots of inheritance simply because I know the code in question needed a lot of casting, but my gut feeling is that generics doesn't have an awful lot to do with inheritance and re-jigging a class that relied on inheritance to use generics is barking up the wrong tree.
I'd really appreciate some informed comments before I go trundling off down a path that is going to end with reams of pointless code.
Thanks,
Steve

IMO the most useful feature of using Generics is compile time typesafety.
Consider the pre-1.5 code for making a LinkedList that contains strings:
LinkedList l = new LinkedList();
l.add("Hello world!");
l.add(new Integer(100));    // <---- runtime exceptionInstead, you can now write the code like this:
LinkedList<String> l = new LinkedList<String>();
l.add("Hello world!");
l.add(new Integer(100));    // compile time exceptionIf you accidentally put the wrong type in a Collection you will get a nice compile time exception instead of a ClassCastException at runtime.

Similar Messages

  • RT - PID Gains - where and when to use them

    The attached is example code for controlling a temperature chamber. The question is where and when to use PID Gains? This code looks as though the PID Gain is used for the variable/parameter temperature (i.e. the temperature is the controlled variable).
    So would there be just one PID Gain per controlled variable/parameter (temperature in this case) or would each device controlling temperature in the system get a PID Gain?
    In this example, the fan and lamp are controlling the temperature.
    Attachments:
    Exercise 8-1.zip ‏171 KB

    Russ_in_Louisville wrote:
    I came here for help as this is where NI pointed me in their failure. I did not come here to get my "mental model" attacked.
    Can you accept that your model of the system might be wrong, though? In this thread from a few weeks ago, multiple experienced users told you that what you had on your block diagram was an array, and yet you insisted - repeatedly - that what you had was a cluster. Your model was that the item on the block diagram was a cluster, leading to the question "how do I get an index display on it?" which made no sense, because the item was in fact an array. And, when you finally realized you were wrong, you couldn't even admit it or thank the people who pointed out your error - it just "turned out" that the constant wasn't what you thought it was. I am trying to tell you that you are making a similar error here by asking questions about the system that do not correspond to what the system actually does.
    "Parameter/variable" isn't clear. There is correct terminology. A PID controller has, as inputs, a process variable and a setpoint. The process variable is the parameter you want to control, such as temperature. The setpoint is the desired value of the process variable. Let's say you do have a temperature control system where there is both a heating system and a cooling system (again, not the situation in your sample code). The two systems could both be driven by PID and share the same setpoint and process variable. Some control options for this system:
    - a single PID controller with one set of gains, where a negative output drives the cooling system and a positive output drives the heater (or some variation on this), if both the heater and chiller have similar performance characteristics.
    - two PID controllers, each with a set of gains, one controlling the heating and one controlling the cooler.
    - a combination of these two: a single controller with gains that are selected based on the setpoint or process variable, which is known as gain scheduling. The advantage to a single controller is that you'd never have the two controllers fighting each other.
    You could also have a code that controls several similar processes (for examply, multiple identical temperature chambers). In that situation you could have a single set of PID gains but multiple controllers each with a different setpoint and process variable.
    So there's not a simple yes/no answer to when you need a separate set of PID gains or an additional PID controller. It depends on the characteristics and design goals of your system. Does that help?

  • When and Where and how to use Proxies

    hi
    New to Xi Can anyone explain When and Where and how to use Proxies
    Mohit

    Proxies: are interfaces which will get executed in the application system.They can be created only in the system from message interfaces using the proxy generation functions.
    The biggest advantage of the proxy is that it always by passes the Adapter Engine and will directly interact with the application system and Integration engine - so it will and should give us a better performance.
    The literal definition of a proxy is an object / process authorized to act for another; an agent or a substitute. In simpler terms, proxies in the XI context are objects used to encapsulate the creation (from a sender system) or parsing of XML (at a receiver system) as well as the communication with the relevant runtime components required to send or receive those messages. The Proxy Runtime controls these objects / processes, and can itself be controlled by the applications it communicates with.
    The Proxy currently has the following components available:
    1. ABAP Proxy – Communication using XI or Web Services
    2. Java Proxy– Communication using XI (J2EE)
    JAVA Proxies:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a068cf2f-0401-0010-2aa9-f5ae4b2096f9
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f272165e-0401-0010-b4a1-e7eb8903501d
    ABAP Proxies:
    /people/sap.user72/blog/2005/12/13/integration-builders-through-proxy-server-part--2
    /people/ravikumar.allampallam/blog/2005/03/14/abap-proxies-in-xiclient-proxy
    /people/arulraja.ma/blog/2006/08/18/xi-reliable-messaging-150-eoio-in-abap-proxies
    /people/stefan.grube/blog/2006/07/28/xi-debug-your-inbound-abap-proxy-implementation
    /people/michal.krawczyk2/blog/2006/04/19/xi-rfc-or-abap-proxy-abap-proxies-with-attachments
    /people/sukumar.natarajan/blog/2007/01/07/how-to-raise-alerts-from-abap-proxy
    /people/sravya.talanki2/blog/2006/07/28/smarter-approach-for-coding-abap-proxies
    ON SDN TV
    https://www.sdn.sap.com/irj/sdn/advancedsearch?query=abap%20proxy%20xi&cat=sdn_all&start=11#
    Proxies communicate with the XI server by means of native SOAP calls over HTTP .RFC does not, so you have to convert from SOAP to RFC calls and vice versa. So XML conversion is required.
    ABAP Proxies uses Webservice and Http Protocols. And if you use RFC it is mainly meant for Sync. call. But Proxies is used for both Sync and Async.
    If you use ABAP Proxy , you can reduce the overhead calling the function again and again.
    /people/vijaya.kumari2/blog/2006/01/26/how-do-you-activate-abap-proxies - Activate Proxy
    /people/siva.maranani/blog/2005/04/03/abap-server-proxies - ABAP Server Proxy
    /people/ravikumar.allampallam/blog/2005/03/14/abap-proxies-in-xiclient-proxy - ABAP Client Proxy
    Re: JDBC Sender select/update problem
    If u generate proxy for outbound interface then its client proxy and for inbound interface its server proxy.
    In client proxy u can call the method to send messages but u can't modify it but in server proxy its possible to write a user code within the method to execute proxy.
    CLIENT PROXY:
    A WSDL description from a UDDI server (or an Internet page) is usually used to make a service executable in the Internet and to describe the interface of this service. You require a client proxy and not a server proxy to call this service by using the Web service infrastructure.
    SERVER PROXY:
    You can only generate ABAP server proxies from a WSDL description if they originate in the Integration Repository.You can also generate server proxies for Java and client proxies for ABAP from message interfaces.

  • I pick a photo, make a copy, add a mask and when I use a brush nothing happens to the mask or the picture. White or black?

    I pick a photo, make a copy, add a mask and when I use a brush nothing happens to the mask or the picture. White or black.

    If I understand you correctly, you have
    Opened an image, and copied the background layer. 
    Added a layer mask, and finding that painting in the mask makes no difference whether you paint with black or white.
    That is what you would expect to happen if both layers are identical.  To demonstrate, make a change to the copied layer.  Either change the blend mode to Multiply, or lower the opacity, or paint big red stripes across it.  Now when you paint with black, the red stripes will disappear where the mask is black, and be visible where the make is white.

  • How to know where and when my account logged in by...

    Recently my account was used by someone and sent out a misleading message, which cause a great trouble to me. I sensed the one was in purpose. Can I check where and when my account was used on that date? How? Please help !!! waiting for your reply...

    hi dominic.
    thanks for the help and the links.
    there is something terribly lacking in mac UI with respect to this unless i am missing something. if i do a search in Spotlight i see results and even when i see the file i want to know something about i have to OPEN FINDER which shows a ton of results (including hundreds if not thousands of eml file that i have to call mac and probably pay to find out why they are still showing up when prefs in Spotlight say to not show them...)  and only then can i actively select the file and have it show a file path at the bottom of the finder window.
    this is maddening. isn't there an option to show this information in Spotlight or to show this information WHEN THE FILE IS OPEN (apologies for the caps). i mean, if i have a file open, maybe i don't know /where/ it came from for some reason.
    for instance, if i am in a hurry and i open the file directly from Spotlight i can edit it and save it but i still have no idea where it resides on my hard drive. similarly if i open a file directly from spotlight and DUPLICATE a file and i want to save it as Version 2 - i have to - - - - well i guess i have to run another search for the file i just opened and am working upon in order to just save the dang file to the same location the original is in?
    i mean, the links are showing that i should open Get Info but i think i need to see the file in finder to run this command anyway since i have to right click on the file itself.
    maybe i am missing something but can't MAC OS just show me the FILE PATH at the top of the document like it does in Finder and also show me the FILE PATH in Spotlight? seems like the current implementation is like a big game of hopscotch for no good reason except the information is not shown to the (power) user.
    maybe i am missing a new feature in ML or in Mavericks or maybe i am using the wrong terms in the original title?
    THANK YOU

  • HT3702 the billing info keeps saying my security code is invalid and when i use a different debit card it says my bank records dont match WTH

    the billing info keeps saying my security code is invalid and when i use a different debit card it says my bank records dont match WTH

    Pease dont' waste your time with that useless article. Carolyn has been warned many times before to stop posting that and waisting people's time.
    This error is a little generic at times and there are a few things that could be happening here. Please put in a ticket here for an advisor to check into details:
    iTunes Store Support
    http://www.apple.com/emea/support/itunes/contact.html
    There is no need to keep frustrating yourselfs at the moment.

  • I just purchased Export PDF, and when I use it, it opens them in WordPad (which I never use) instead of Word. Thus, the pictures are not there, and the fonts are changed. How do I get into Word?

    I just purchased Export PDF, and when I use it, it opens them in WordPad (which I never use) instead of Word. Thus, the pictures are not there, and the fonts are changed. How do I get them imported into Word?

    Hi,
    I checked your account,your Export PDF subscription is in 'Pending' status.
    Once it gets confirmed you will be able to use it.
    Please let us know if you require further assistance.
    Regards,
    Florence

  • I sent in my iPhone 6 for repair. I used restore on the loaner phone I was given, and the contacts, texts, reminders, and Safari pages all showed up. My phone is back, and when I used the restore function again, those items are missing.

    I sent in my iPhone 6 for repair. I used restore on the loaner phone I was given, and the contacts, texts, reminders, and Safari pages all showed up. My phone is back, and when I used the restore function again, those items are missing. I do not use iCloud because I have no wifi at home, limited data available for regularly backing up, and I have a 64GB phone and don't wish to pay to upgrade from the 5GB iCloud storage. Am I doing something wrong? It worked so seamlessly on my loaner phone that I am completely stumped as to why it will not restore those items to my original phone again.

    The iphone is designed to be synced to your computer or cloud service.  Your contacts should be in whatever program/service you have chosen to sync.
    If you have failed to do this, then they are likely gone.

  • What's wrong with my iPhone? I put it on the charger it's says it's charging but nothing happens and when I use it while it's charging it starts to die and stops at 1%

    What's wrong with my iPhone? I put it on the charger it's says it's charging but nothing happens and when I use it while it's charging it starts to die and stops at 1%

    Please help

  • I am importing videos from my canon sl1 to my macbook when i use iphoto is says "iPhoto cannot import your photos because there was a problem downloading an image." and when i use image capture it says "An error occured while importing. The item 'MVI_1040

    I am importing videos from my canon sl1 to my macbook air when i use iphoto is says "iPhoto cannot import your photos because there was a problem downloading an image." and when i use image capture it says "An error occured while importing. The item ‘MVI_1040'' Thanks in advance

    Can you access the images on the phone with Image Capture (in the Applications Folder) ?

  • When to use PGA_AGGREGATE_TARGET and when to use temporary table space?

    Hi, all.
    I am a little confused with regard to when to use pga work area, and
    when to use temporary tablespace?
    Is there any one who could give me an advice or a document?
    Thanks in advance.
    Best Regards.
    Message was edited by:
    user507290

    You are more than a little confused... What has one to do with the other, do you think?
    All Oracle documentation is at http://tahiti.oracle.com - I suggest you start with the Concepts manual of your version

  • SAP Query (SQ01) who and when to use the report

    HI Experts!!!
    Is there somewhere recorded information:  who and when to use the report from SAP Query (SQ01)?
    Thanks

    Hi
    This topic doesn´t belong to the Service Marketplace Area.
    regards Martin

  • When to use jsp,and when to use servlet?

    I think that jsp and servlet can realize the same functions, because when run a jsp, it is transferred to a servlet program, so when to use jsp and when to use servlet?
    I am now developing the input interface for a website, I just use jsp and javabean to connect to weblogic and database, and I didn't use servlet, Is there any unseemliness?
    Thank you!

    IMHO I use servlets to control the flow between my jsp's based on a number of factors in a webapp. For instance, user authorization. If a user has the authorization to conduct various administrative functions on an application (like change user rights, reset passwords etc) they will have access to specific buttons or links on some screens that others will not. I use servlets to establish what access rights a user has and direct them to the appropriate pages. I also use servlets to test data validity on form input screens. I know that I can also do this with JavaScript but that can be disabled by the client and in order to prevent that I also double check the form input from a servlet. All my jsp's do is display the results of a business process (which is held in a JavaBean or EJB) and the servlets act as the controllers for the application, connecting to multiple databases, verifying application state, flow control etc. I try to keep the jsp as simple as possible as some of them are maintained by html developers who lack the necessary experience to write java code. I hope this helps.

  • I have photoshop elements 12 and when I use the font it crashes the program, how can I fix this?

    I have photoshop elements 12 and when I use the font tool it crashes the program, how can I fix this?I have a macbook pro

    Use the crop tool.
    On the tool's option bar, type 300 px & 200 px, and the desired resolution.

  • I have the Photoshop Elements 11 and when I use the stamp effect the image becomes totally black. It used to have my line drawing in white, now, just a black image. I need the stamp effect. also, most other effects simply crash the program.

    I have the Photoshop Elements 11 and when I use the stamp effect the image becomes totally black. It used to have my line drawing in white, now, just a black image. I need the stamp effect. also, most other effects simply crash the program.

    Which operating system are you using?
    Some filters like Filter>Sketch>Stamp need to have two different colors for the Foreground and Background set in the toolbox.
    Press the D key to set the default toolbox color swatches to Black and White and then try the Stamp filter.
    If your using mac os x 10.9 or 10.10, then some of the filters under Filter>Sketch will crash pse 11
    They are Filter>Sketch>Comic, Graphic Novel and Pen and Ink
    Otherwise resetting the pse11 editor preferences might resolve the crashing.
    Go to Photoshop Elements Editor(Edit)>General, click on Reset Preferences on Next Launch and then restart the pse 11 editor

Maybe you are looking for

  • How do I change the name of my computer

    How do I change the name of my new iMac, my wife set it up and she named it wrong and I want to name i differently. Now I have 2 computers on the network with her name as the computer name at least one has an 's after the name, but I just want a tota

  • Hp photosmart 6525 icon pinned taskbar not working

    printer icon pinned to taskbar suddenly stopped opening the window for choices of what you wanted to do with your printer, and now just displays the following window...

  • Popping up values into dropdown field while form initialize

    I have a two drop down boxes  one showing Gender male/ female , another showing  caste_group code like BC,SC,ST,OC etc.. I have xml record data with  name of the persons , employement no, gender, caste . so while form intialize time  i want to pop up

  • Finder window opens on startup

    All of a sudden, a few days ago, I started getting an open finder window when starting up the computer. It doesn't do it every time; I think it does it the first time I start the computer on any given day. I do not have the finder set up as one of my

  • How to maintain the state(opened/closed) of a Hierarchical expanding list

    Hi, I've created a list with template "hierarchical expanding". When I click on the list node to go to a page, page related to the node appears but the tree doesn't remain expanded. It always shrinks back to the highest level. Please suggest a soluti