Generics and Auto-boxing not working together

Why does the following code produce a compile error:
"Type mismatch: cannot convert from char to Character."
public class X<Character> {
     private Character c;
     private Integer i;
     public X() {
          c = 'a';
          i = 12;
}Note that if I change the class declaration to class X<Integer>, I'll get the error about converting from int to Integer, but the char error will disappear.

I believe that the <Character> type parameter is hiding the java.lang.Character class. Your code is equivalent to this:
public class X<T> {
     private T c;
     private Integer i;
     public X() {
          c = 'a';
          i = 12;
}So what you really want is something like
public class X<T> {
     private Character c;
     private Integer i;
     public X() {
          c = 'a';
          i = 12;
}or maybe this, depending on what you're really trying to do
public class X<T extends Character> {
     private T c;
     private Integer i;
     public X() {
          c = 'a';
          i = 12;
}Of course, since Character is final, that doesn't really make sense either.
Perhaps you could explain a bit more about what you're actually trying to accomplish.
Edited by: jverd on Feb 26, 2010 11:24 AM
Edited by: jverd on Feb 26, 2010 11:25 AM

Similar Messages

  • Auto keyframe and auto transition not working

    auto keyframe and auto transition not working and I have a creative cloud, in addition the auto keyframe works in the getting startel lessons....

    In order to use these you need to have the autokey frame and transition selected
    OFF   ON
    and have the first key checked then move the playhead to the new position and it should add the transition.
    Did you try this and it is not working?.

  • Auto Boxing not working in Java 6?

    Hi All,
    I am studying and practicing to become Java Certified and I am just using an example from the Java Certification Guide Chapter 11 Swing Components from Sybex for Java 5.
    I am using Eclipse and the latest Java 6 SDK in WIndows XP.
    The code below runs fine in Solaris 10 using Java 1.5.0_14-b03:
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class StringLengthTableModel extends AbstractTableModel {
         private String[] strings;
         public StringLengthTableModel(String[] strings) {
              this.strings = strings;
         public int getRowCount() {
              return strings.length;
         public int getColumnCount() {
              return 2;
         public Object getValueAt(int row, int col) {
              if (col == 0) {
                   return strings[row];
              } else {
                   return strings[row].length();
         public String getColumnName(int col) {
              return (col == 0) ? "String" : "Length";
         public static void main(String[] args) {
              JFrame frame = new JFrame();
              String[] strings = { "January", "February", "March", "April", "May",
                        "June", "July", "August", "September", "October", "November",
                        "December" };
              StringLengthTableModel model = new StringLengthTableModel(strings);
              JTable table = new JTable(model);
              frame.getContentPane().add(table);
              frame.setSize(500, 250);
              frame.setVisible(true);
    However in Windows XP and using the latest Eclipse IDE and the Latest Java 6 SDK I get:
    Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
         Type mismatch: cannot convert from int to Object
    The questionable method line is
                   return strings[row].length();
    in the method
         public Object getValueAt(int row, int col) {
              if (col == 0) {
                   return strings[row];
              } else {
                   return strings[row].length();
    Any ideas????
    You would think and hope the latest release of Java like Java 6 would be backward compatible with the auto boxing and auto un boxing features that were introduced in Java 5.
    Any comments, thoughts, ideas would be appreciated.
    Thanks,
    Carlos A. Morillo
    [email protected]

    CarlosMorillo wrote:
    Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
         Type mismatch: cannot convert from int to ObjectGo to that line in Eclipse and look for the red squiggly line. Click on the I symbol next to it. At a guess the project is set up to work in 1.4 mode.
    Also learn to love the "Problems" panel. This should not have been a runtime error.
    Any ideas????Your project is in 1.4 mode. Right click on the project in the "Project Explore" window. Select properties, select "Java Compiler", check the "Enable project specific settings" and make sure the little drop downs all say "6.0".

  • Yoga 2 Pro tent mode and auto-rotate not working

    I have had a Yoga 2 Pro since June. Recently the Tent mode and auto-rotate features do not work.
    When I put the Yoga 2 Pro into Tent mode the keyboard and touch pad are still active underneth. However, they shutoff when in tablet mode. Lenovo Transition starts automatically and is running.
    Auto-rotate does not work at all now. The screen is un-locked.

    Dear NX3
    Welcome to Lenovo forums
    Please try to uninstal the Lenovo transition program and download the version in the below link and instal it
    http://support.lenovo.com/us/en/downloads/ds038767
    Thanks
    Did someone help you today? Press the star on the left to thank them with a Kudo!
    If you find a post helpful and it answers your question, please mark it as an "Accepted Solution"! This will help the rest of the Community with similar issues identify the verified solution and benefit from it.
    Follow @LenovoForums on Twitter!

  • Magnetic lasso and auto sharpen not working correctly

    anyone having this problem with PSE 3.0

    Which operating system are you using?
    What is not working with the Magnetic Lasso Tool and Auto Sharpen?
    Have you tried resetting the photoshop elements 3 preferences?
    To reset the preferences:
    Press and hold the Shift+Alt+Ctrl (windows) or Shift+Option+Command (mac) keys just after starting the launch of the pse 3 editor.
    Keep holding the keys down until you get a dialog asking if you want to delete the photoshop elements settings file
    Press Yes to reset the preferences.

  • Passwords and Auto Fill not working...

    All of a sudden, new passwords are not being retained and auto fill doesn't work at all. I've repaired permissions, checked every setting I can think of. What should I try next?
    Thanks,

    I had a similar problem with autofill. Repairing permissions with Onyx seemed to work. (But first, double-check that Autofill is enabled and your "me" Address Book card is correct.)

  • Hints FIRST_ROWS and order by not working together

    Hi,
    We are facing an issue like we are using hint FIRST_ROWS with a query which have a order by clause, if we are giving both together
    it is not working and if we remove either order by or hint it is working
    SELECT /*+FIRST_ROWS*/ * FROM (SELECT MYROWS.*,
    ROWNUM RN FROM (SELECT * FROM V_REPORT WHERE START_DATE &gt; '22-SEP-04'
    AND END_DATE &lt; '22-SEP-08' AND
    (GEO_ID in (select GEO_ID from loc where anc = 0))
    ORDER BY
    ENTITY,OPERATION,NAME
    MYROWS)
    A simliar query from other view is working fine.
    Please help me on the same.

    David_Aldridge wrote:
    Solomon Yakobson wrote:
    Well, ORDER BY implies all rows must be fetched first and then ordered. So yes, FIRST_ROWS does not make much sense in that situation, does it?.
    SY.Not in every case -- sometimes an index can be used by the optimizer to returen rows in the correct order without having identified the entire result set.
    FIRST_ROWS is deprecated in favour of FIRST_ROWS(n), by the way. http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/usingpe.htm#i1009413
    And even if the result set needs to be ordered and no index can be used to avoid the sort operation Oracle offers for "top n" and "pagination" queries the "ORDER BY STOPKEY" optimization which only keeps the top n rows to sort (probably in memory if n is small enough) and eliminates the remaining ones which can make a huge difference if the volume to sort is large.
    I've written a note about issues like that recently.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • My itunes and iphone are not working together. all my software is up to date. what i can do? i need to manage my phone!!

    I'm getting extremely frustrated with my iphone and mac.
    i have the iphone 4, and the mac is leopard.
    I plugged my phone it to manage my music, and a message popped up saying i needed software 10.6.8 or higher.
    so i downloaded the 10.7. it's still not working!
    i have very little space left on my phone and i need to manage everything.
    what do i do??
    someone please help!!!!

    We need clarification here.
    Please don't just state version numbers, also state which software.  iTunes 10.7 requires OSX 10.6.8 or higher.  Leopard is OSX 10.5.8.  You have two alternatives right now.  One is to stay with Leopard for a while (ultimately you should upgrade) and install iTunes 10.6.3 which is the last version to work with Leopard.  This should work with iOS6 on an iPhone4.  The other is to call Apple and order OSX 10.6 (Snow Leopard) and upgrade the computer to 10.6.8 which will allow you to run iTunes 10.7.  The caveat is we know nothing about which computer you run and if it even can run any system higher than Leopard.
    Here is iTunes 10.6.3
    iTunes 10.6.3 - http://support.apple.com/kb/DL1575
    If you want to try upgrading:
    Get more information about your computer. Go to the Apple in the upper left corner of any window, then "About this Mac" and "More Info..."  Copy and paste the information here, but omit the serial number and Hardware UUID (if present).  If it says something about Intel or Core Duo or Core 2 Duo in the processor you can upgrade to Snow Leopard (assuming you have sufficient RAM/"memory").  If it says PPC or PowerMac, you cannot.
    Kappy 08/2012 post on upgrading to Snow Leopard, then Lion or Mountain Lion -  https://discussions.apple.com/message/19401628 - including how to get Snow Leopard and Lion since Apple removed them from the online store. 
    It would help when posting issues here if you would state exact error messages you see.  "It's still not working!" while a description of the situation does not speed us to a diagnosis of the underlying issue.

  • My Keynote and iPhoto are not working together to build stacked photos

    I am new to the Mac world (1st day on the Mac) and I am trying to stack 3 photos on to one Keynote slide. I cannot get my photos in iPhoto to come up when I click on Media.
    What am I doing wrong?

    We need clarification here.
    Please don't just state version numbers, also state which software.  iTunes 10.7 requires OSX 10.6.8 or higher.  Leopard is OSX 10.5.8.  You have two alternatives right now.  One is to stay with Leopard for a while (ultimately you should upgrade) and install iTunes 10.6.3 which is the last version to work with Leopard.  This should work with iOS6 on an iPhone4.  The other is to call Apple and order OSX 10.6 (Snow Leopard) and upgrade the computer to 10.6.8 which will allow you to run iTunes 10.7.  The caveat is we know nothing about which computer you run and if it even can run any system higher than Leopard.
    Here is iTunes 10.6.3
    iTunes 10.6.3 - http://support.apple.com/kb/DL1575
    If you want to try upgrading:
    Get more information about your computer. Go to the Apple in the upper left corner of any window, then "About this Mac" and "More Info..."  Copy and paste the information here, but omit the serial number and Hardware UUID (if present).  If it says something about Intel or Core Duo or Core 2 Duo in the processor you can upgrade to Snow Leopard (assuming you have sufficient RAM/"memory").  If it says PPC or PowerMac, you cannot.
    Kappy 08/2012 post on upgrading to Snow Leopard, then Lion or Mountain Lion -  https://discussions.apple.com/message/19401628 - including how to get Snow Leopard and Lion since Apple removed them from the online store. 
    It would help when posting issues here if you would state exact error messages you see.  "It's still not working!" while a description of the situation does not speed us to a diagnosis of the underlying issue.

  • Screen locking up and auto rotation not working on phone wakeup

    Since updating to iOS8 my iPhone 5 and 5s will lock up when waking the phone.  I also have noticed that the screen rotation does not work riight away and is sluggish.  Certain apps tend to freeze which could be that they need an update themselves.  It is a shame that Apple has resorted to using its customers as beta testers for their software.  As a die hard Apple fan it is getting harder to stay true to the company.  Apple should be leading not playing catch up which is why I think theses major software issues develop.

    Model Name: P55W-B5112
    Part Number: PSVP3U-003003 Support site here If it is brand new and not working correctly then I suggest bringing it back and requesting a replacement or refund.  It should work perfectly brand new without having to fuss around. 

  • Bluetooth Mouse and Thinkpad T520 not working together at all

    Hi All (first post),
    System:
    Lenovo T520
    Windows 7
    Microsoft Bluetooth mouse
    Problem: Not working at all, or working only sporadically.
    History: Laptop is a bit over year old (warranty ends in June 2015 IIRC). The sales clerk recommended a bluetooth mouse, so I bought a Microsoft Bluetooth 5000. After the initial pairing difficulties were resolved, they worked swimmingly for about a year. Then I started more and more frequently having to re-pair them (remove device, let Windows find it again, pair them,...). As the mouse had taken a bit of beating, I bought another one a week ago. Didn't really help. The first time I asked Win7 to find the device, it couldn't. The Bluetooth radio was on, and the mouse had a fresh set of batteries, and all the other braindead suggestions of Win7 were eliminated. The bluetooth radio was working, because it detected the neighbors daughter's smartphone through a concrete wall, but not the mouse. I kept pressing the button in the bottom of the mouse that presumably makes it broadcast "I'm here".
    I moved to another room. This time detection and pairing up the device went fine. But after I had switched the laptop and the mouse off, and rebooted - nothing happened. I had to go through the remove/add device cycle again. Moving to a different room again. At first nothing. Then Windows finds the device, but gives the error code 0x800070015 (or something like that, not sure about the number of zeros), and fails to configure it.
    Any idea what is going on? Why is this becoming progressively worse?
    Elsewhere in this forum it was suggested that I should disallow windows to power off USB root hubs. I tried that but it had no effect.
    Regards,
    Jyrki

    Sorry. The error code was 0x80004005. This is the code I get from Add Device ->, when I try to enter 0000 as the paring code (suggested by the mouse start guide. If I try to pari them without a code, Control Panel first indicates that the piece of Hardware was added ok, but it before I get any use out of the mouse, the freshly added pic of the mouse disappears. The red/green light on the mouse never stops blinking.

  • Is there any way to get around the issue of AE7 and Lion OS not working together?

    I use AE7 for graduate studies and business and just can't understand why it won't work together.

    Why?  Because Adobe has other priorities, in simplest terms.  As with most commercial software producers, Adobe is looking to maximize their profits while their software developers are constrained to operate and optimize within their available development budgets, and also while delivering the corporate plans and schedules set by Adobe management.
    What to do for this case?  Migrate off of the Adobe software, migrate off of Mac OS X, deploy a virtual machine or Boot Camp (with Snow Leopard) and Adobe After Effects, or wait for Adobe to sort this out.  For sufficiently large-scale customers of Adobe, they can chat directly with Adobe management around whether a bounty will expedite the work.  (These are the usual answers, of course.)

  • CS 5.1 - Manual and Auto upgrades not working

    I originally posted this in the Camera Raw forum as I had have been trying to upgrade Camera Raw to 6.7 on my windows 7(32) machine running CS5.1. without success.  It now appears that I am not able to carry of any updates in CS5.1 either through the program update routine or by download.  All programs seem to be working fine apart from this.
    If I try using Help>Update Adobe Application Manager opens, goes through an apparent download of all the updates but I see little data stream comming in and then staps saying  there is a download problem please try later.
    If I dowload the update direct for the Adobe site the download is fine but when I run AdobePatchInstaller.exe to istall say Camera Raw 6.7 Adobe Application Manager opens and thinks for a little whlie before giving  "an error installing the update"
    I have tried Adobe support adviser but this was of little help indicating "cpsid_90243r4: Error DW020 or DW050 occurs during installation - Creative Suite 5.5, Flash CS5.5, Flash Builder 4.5" which is apparently an error sometimes seen during initial installation.
    Running Photoshop and the updates as administrator does not help.
    Anyone any ideas other than a complete reinstall?

    Hello! is bridge set to auto-run as your start your user session? this might cause problems. Try disabling that option from its preferences.
    What other programs are running?
    What version of ACR are you using for the moment?
    Is the install path a non-standard one?

  • Microsoft word 2013 function home and end keys not working together on HP Envy X2

    Please help I've tried out Microsoft Office Word 2013 on two HP Envy X2 11.6" laptops/touch screen with keyboard and when I am in a Word document and am at the end or beginning of a document and select the FUNCTION KEY AND THE HOME OR END KEY, it does nothing. This is not the case in Internet Explorer or a web browser.  There is a problem with the HP keyboard and Office 2013 or maybe any Word app. Help me as I use documents alot and rely on this function heavily.  I can only page up or scroll up using the bar. It is not ideal.
    Astaastra

    Hi rosedoc12,
    I have done some research and I have found a document that will show you how to disable or lock the fn key.
    http://h10025.www1.hp.com/ewfrf/wc/document?cc=us&​lc=en&docname=c02035108
    Thank you,
    Please click “Accept as Solution ” if you feel my post solved your issue.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Thank you,
    BHK6
    I work on behalf of HP

  • IPod Touch and iTunes Will Not Work Together.

    I just received a new iPod Touch 32GB yesterday and have had nothing but troubles trying to get it to play nicely with iTunes. The Touch is currently version 1.1.5/4B1 (I believe updated to this sometime yesterday).
    I am running iTunes v. 7.7.1 (11). When I connect the Touch to my iMac with iTunes running (even though I have it checked, just plugging the Touch in does not open iTunes) nothing happens for a long time and then I get a spinning beach ball which I have let go on for more than 20 minutes at one time.
    The Touch and iTunes work fine independently. The last two times after force quitting iTunes, I have received the following error: iTunes could not connect to the iPhone (??) "" because an unknown error occurred (OxE8000035).
    Does anyone know what this error is, & how do I resolve these issues?
    <Edited by Moderator>

    At least atm -
    I have re-installed iTunes after restarting the iMac and then restarted again, the Touch connected and showed right away after that and I am happily, currently syncing.
    If it goes bottoms up again, I'll be back!

Maybe you are looking for