For any type selector

This might be covered elsewhere in the forum but my searches have been fruitless.
Given:
public Object genKey(Class clazz) {
}and
public interface Keyed<K> {
  public void setKey(K key);
  public Class<K> keyClass();
}this is a valid use:
  Keyed<X> keyed = ...;
  Object key = genKey(keyed.keyClass());
  keyed.setKey(keyed.keyClass().cast(key));
...Now, say I have some framwork code that checks that an arbitrary object implements Keyed and assigns a key if it does:
if ( Keyed.class.isAssignableFrom( obj.getClass() ) {
  Keyed keyed = (Keyed)obj;
  Object key = genKey(keyed.keyClass());
  keyed.setKey( keyed.keyClass().cast(key));
...Of course, the call to setKey generates a warning. But there is enough information there for the compiler to determine that the call is type-safe.
What I seek is a way to declare the variable keyed with the semantics "for any type Y" as the generic selector. A wildcard doesn't work because it doesn't provide a handle to the selected type.
Is there some way to to express this meaning in Java 5 or am I stuck with the warning?
if ( Keyed.class.isAssignableFrom( obj.getClass() ) {
  Keyed<any Y> keyed = (Keyed)obj;
  Object key = genKey(keyed.keyClass());
  keyed.setKey( keyed.keyClass().cast(key));
}Tia,
-=greg

I omitted some explanation to keep it simple, but I probably made it less clear.
this is a valid use:
What do you mean by "valid use"? Do you mean it
"compiles"? Of course, it does compile, as cast()
takes any Object as parameter, regardless if the cast
will succeed.I understand this. By valid, I mean the it is type-safe from the compiler's
point of view. I know that an invalid cast will throw an exception at runtime
and that by using the cast call, I assume responsibility.
if ( Keyed.class.isAssignableFrom( obj.getClass()  )
Keyed keyed = (Keyed)obj;
Object key = genKey(keyed.keyClass());
keyed.setKey( keyed.keyClass().cast(key));
...Of course, the call to setKey generates a warning.
But there is enough information there for the
compiler to determine that the call is type-safe.No, it's not. You are using raw type Keyed here, so
there is no type-safety involved. The cast may
succeed or fail, who knows? Again, just talking about the compile-time safety interpretation here. Ignore
the potential runtime exceptions.
There is enough information here in the sense that any Class instance
returned from the keyClass() call is guaranteed to be compatible with the
parameter type of the setKey(..) call--according to the interface definition
alone. The interface implementation could, of course, return all kinds of
wrong things. But the issue I was trying to address in this post has only to do
with the compiler warning issued in the setKey(..) call.
You can use Keyed<T> keyed = (Keyed)
obj; so you actually see the origin of the
warning. Information on T only is available at
compile-time. There is no Keyed<T>.class, so you can
neither test its assignability nor cast to it. Hence,
the warning about erasure. The rest of your code
still remains the same, unsafe code, while the
compiler gets forced to accept it as type safe.I know this. I am simply trying determine if there is a way to, as a
compile-time benefit only, introduce a binding of the "for any" kind. It is a
useful semantic that I don't think is available in the language.
A first thing would be to parametrize genKey, e.g.:
public <T> T genKey(Class<T> clazz) throws
InstantiationException, IllegalAccessException {
return clazz.newInstance();
And, indeed, it is actually implemented in such a fashion--I provided the
version I did because it spells out the problem more clearly. The problem
is that in the framework code snippet ONLY, there is no way to express the
selector because, as you have pointed out, it cannot be determined.
So, the original question is the same--and I think the answer is probably
"no": can an arbitrary selector be introduced with the meaning "for any?"
Wildcarding is inches from being the right meaning but there is no selector
introduction.
Secondly, you will have to define a type to be used
in the context, so you can connect outcomes to a
@SuppressWarnings("unchecked")
Keyed<T> keyed = (Keyed) obj;
Right. Doing this is closest to what I was seeking but it is not a true
representation of the semantic (i.e. it still generates a warning).
So, what I'm hearing so far is, "no, there is not a syntactic construct that will
express a 'for any selector' concept other than to force it and accept the
resulting warning." That answer is fine with me, I just didn't want to miss out
on any better way.
-=greg

Similar Messages

  • How can I find Top music charts for any type of music? Reggae, French etc.

    Itunes used to have a way to see all the charts for any type of music. 60's, international, Latin, but I don't see a way to find this anymore. Can anybody help me?

    Charts by those categories no longer exist in the iTunes Store, unless they've been hidden somewhere I can't find. Most of those charts were compiled by Billboard and were removed at least a couple of years ago, probably due to licensing issues.
    You can, however, hover your cursor over the Music tab, click the arrow, and select the listed genres, and the page for that genre will list the Top Songs for that genre only.
    Regards.

  • Wildcard for any types of Array?

    Hi,
    I want to create a method who convert an array of any type
    to an array of type Object.
    Is there a way to use a wildcard for the arrays like "T[]"
    My compiler - JBuilder 2005 - don't accept this.
    Olek

    You will have to build special cases for each primitive type. Basically, a series of (inputArray instanceof int[]) conditions, and in each you need to copy from the primitive array to the Object array (or the primitive-specific wrapper such as Integer[], depending on what you want).
    System.arraycopy() will not copy between primitive and reference type arrays, so that won't work.

  • Conditional Columns in Select Statement for any type of Report

    Okay so I had a requirement to conditionally show columns on a report when the data in the column was not null. I played around the "vertical" report mentioned in other posts but it didn't work well for my needs. Also I know that there is a javascript solution for this as demonstarted in Denes Kubicek's app (which was copied from Vikas :) ). Anyways listed below is my approach.... Hope this can help anyone else out as it's just pl/sql returning sql. Also you will need execute on dbms_sql for this to work.
    declare
    v_count number := 0;
    v_row_count number := 0;
    v_col_name varchar2(100);
    q varchar2(4000) := 'select ';
    v_table_name varchar2(100) := :SOME_TABLE_NAME;
    v_id varchar2(100) := 'num = '||:SOME_APEX_VALUE;
    my_c INTEGER;
    fdbk INTEGER;
    statement varchar2(2000);
    cval_out varchar2(2000);
    nval_out number;
    begin
    select count(*) into v_count from cols
    where table_name = v_table_name;
    for counter in 1..v_count
    loop
    select column_name into v_col_name
    from cols where table_name = v_table_name
    and counter = column_id;
    statement := 'select count(*) '||
    ' from '||v_table_name||
    ' where '||v_col_name||' is not null and '||v_id;
    my_c := dbms_sql.open_cursor;
    dbms_sql.parse(my_c,statement,dbms_sql.native);
    dbms_sql.define_column(my_c,1,nval_out);
    fdbk := dbms_sql.execute(my_c);
    LOOP
    exit when dbms_sql.fetch_rows(my_c) = 0;
    dbms_sql.column_value(my_c,1,nval_out);
    end loop;
    v_row_count := nval_out;
    dbms_sql.close_cursor(my_c);
    if v_row_count > 0 then
    q:=q||v_col_name||',';
    end if;
    end loop;
    if(substr(q,length(q),1) = ',') then
    q:= substr(q,0,length(q)-1);
    end if;
    q:= q||' from '||v_table_name||' where '||v_id;
    end;Hope this helps...
    -David
    Message was edited by:
    rdpatric

    Hi Gints,
    Thank you for your reply. This is my query and
    nvl(TICKET_JOIN.TDQRLV,0) ACC_SHIPPED_QTY,
    TICKET_JOIN.TDSOQS QUANTITY_TICKETED are the columns tha's creating issue. If I comment those columns Index is accessed properly.
    select
    'TKT' SOURCE,
    TICKET_JOIN.TKDO01 HIRE_ID,
    TICKET_JOIN.TKQ101 TRUCK_ID,
    TICKET_JOIN.TKVEHT TRUCK_TYPE,
    1 TRUCK_COMM,
    nvl(TKCMP1,0) TICKET_NUM,
    nvl(TKADTM,0) TICKET_TIME,
    --TICKET_JOIN.TDSOQS QUANTITY_TICKETED,
    0 CHECKIN_TIME,
    --nvl(TICKET_JOIN.TDQRLV,0) ACC_SHIPPED_QTY,
    nvl(DDADTM,0) START_TIME
    from
    (select
    TICKET.TKCMP1,
    TICKET.TKDO01,
    TICKET.TKQ101,
    TICKET.TKADTM ,
    TICKET.TKVEHT,
    TICKET_DETAILS.TDAITM ,
    TICKET_DETAILS.TDQRLV ,
    TICKET_DETAILS.TDSOQS ,
    TICKET.TKCNTF,
    TICKET.TKTRDJ,
    TICKET.TK58GA8
    from
    CRPDTA.F5800091 TICKET_DETAILS ,
    CRPDTA.F5800090 TICKET
    where TICKET.TKCMP1 = TICKET_DETAILS.TDCMP1
    and TICKET.TKTRDJ = TICKET_DETAILS.TDTRDJ
    and TICKET.TKTRDJ = 107085
    and TICKET.TKEV12 <> 'Y'
    and TICKET.TK58GA8='ECSEO'
    and TICKET.TKCNTF = '11') TICKET_JOIN ,
    (select
    DDDOCO,
    DDCNTF,
    DDQTFN,
    DDAITM,
    DDADTM,
    DD58GA8,
    DDTRDJ
    from
    CRPDTA.F5800051 ORDER_DETAILS,
    CRPDTA.F5800050 ORDER_HEADER
    where
    ORDER_HEADER.DHDOCO = ORDER_DETAILS.DDDOCO
    and ORDER_HEADER.DHTRDJ = ORDER_DETAILS.DDTRDJ
    and ORDER_HEADER.DH58GA8 = ORDER_DETAILS.DD58GA8
    and ORDER_HEADER.DHDCTO = ORDER_DETAILS.DDDCTO
    /*and
    (ORDER_HEADER.DHTRDJ = 107085
    OR (ORDER_HEADER.DHTRDJ = 107084 and ORDER_HEADER.DHEV04='Y')
    and TRIM(ORDER_HEADER.DH58GA8) = 'ECSEO'
    and TRIM(ORDER_DETAILS.DDCNTF) = '11' ) ORDER_VIEW
    where TICKET_JOIN.TKTRDJ = ORDER_VIEW.DDTRDJ
    and TICKET_JOIN.TDAITM = ORDER_VIEW.DDAITM
    and TICKET_JOIN.TKCNTF = ORDER_VIEW.DDCNTF
    and TICKET_JOIN.TK58GA8 = ORDER_VIEW.DD58GA8
    and NOT EXISTS ( select 1 from CRPDTA.F5800120 TRUCK_ASSIGNMENT
    where TATRDJ = 107085
    and TACNTF = '11'
    and TA58GA8 = 'ECSEO'
    and TICKET_JOIN.TKQ101||TICKET_JOIN.TKVEHT = TAQ101||TAVEHT )
    Thanks
    GM

  • Running 10.5.8 on Mac Power PC (non-intel) - when I try to download anything I'm only getting .part files this goes for any type of file, large or small.

    I've resorted to running Safari when downloading anything. I really would like to remain with Firefox, but I can't figure anything out. I recently upgraded to 10.5 (Leopard) and that's when the downloading issues started.
    In addition my default location to download files was the desktop, after the OS upgrade, Firefox will not even allow me to choose the desktop to download to.

    Has nobody got any suggestions?

  • SE80 : Source for the tree structure display for any type of Object

    Hi Experts ,
    I have developed a report which takes in a TR .Given a TR , I get the list of objects under it from table e071 table .
    Now , I need all the objects (includes,screen,status,etc) related each of this object  . SE80 perfectly does this in the form of a tree structure but now sure how.
    Is there any Standard Table in which this information is stored or any FM/Method using which these details can be retrieved ?

    Hi,
    You may use this tool : [SDN wiki: ABAP program to read where-used lists|http://wiki.sdn.sap.com/wiki/display/ABAP/ABAPprogramtoreadwhere-used+lists ]
    Sandra

  • Firefox 5 upgrade results in the following error message presented under details. My system is configure for any type of LAN settings since I only have dail-up connection.

    Installation of FireFox 5 after deleting FireFox 3.6v results in the following error message which I cannot resolve or fix. My system is configured with IE 8v and dial-up only.
    "FIREFOX BROWSER 4.0v and 5.0v
    The proxy server is refusing connections
    Firefox is configured to use a proxy server that is refusing connections.
    * Check the proxy settings to make sure that they are correct.
    * Contact your network administrator to make sure the proxy server is working."

    Please try to go to tools, options, advanced, networking, settings, set "no proxy", re-try. More details here: [[options window - advanced panel]].

  • My ringtones don't sound off for any message on my new BB Q10

    I just bought a BB Q10 and a major disappointment so far is that the ringtones do not sound off for any type of message that I enable a ringtone for? 
    I have gone over the steps over and over and I cannot seem to get them to work! 
    Can anyone help with any trouble shooting or helpful information that will help me get my ringtones up and running?
    Much grateful to the community!
    Totsnrocs

    At your Settings > Notifications, what is your profile set to, Normal, Silent, Vibrate, etc.?
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • All SCOM 2012 R2 dashboards are blank on Windows 7 for any user

    All SCOM dashboards are showing up completely blank on several (but not all) Windows 7 machines and a 2008 R2 server (with RDS)...for any type of user. It's not a permissions issue as the same user can RDP to the SCOM Mgt server and view the dashboards just
    fine. It seems to be some underying pre-requisite that isn't there, or isn't working. We've installed the pre-reqs (reportviewer, SQLSsyClrtypes, etc) to no avail. I've also tried doing a "repair" on .Net, and rebooted as described in another thread,
    but that didn't work. I'm guessing it's something baked into our desktop images, but what am I missing

    ...also, we're seeing this event in the application log when the console is opened on an affected machine (but, not necessarily when opening the dashboard)...so, not sure it's 100% relevant. 
    Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. : System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for
    more information.
       at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
       at System.Reflection.RuntimeModule.GetTypes()
       at System.Reflection.Assembly.GetTypes()
       at Microsoft.EnterpriseManagement.Presentation.DeclaredAssemblyLoader.LoadModuleCatalogFromAssembly(IModuleCatalog bootstrapperCatalog, ModuleCatalog catalog, Assembly assembly)
       at Microsoft.EnterpriseManagement.Presentation.DeclaredAssemblyLoader.CreateModuleCatalog(IEnumerable`1 assemblies)
       at Microsoft.EnterpriseManagement.Presentation.DeclaredAssemblyLoader.LoadInternal(IEnumerable`1 assemblies)
       at Microsoft.EnterpriseManagement.Presentation.DeclaredAssemblyLoader.Load(DeclaredAssembly assembly)
       at Microsoft.EnterpriseManagement.Monitoring.Components.ComponentRegistry.<>c__DisplayClass3e.<GetAssemblies>b__3c(DeclaredAssembly declaredAssembly)
       at System.Reactive.Linq.Observable.<>c__DisplayClass413`2.<>c__DisplayClass415.<Select>b__412(TSource x)

  • LabVIEW Certificated MSc student looking for any related job

    I am a MSc student studying Electronic & Computer Based System Design in the UK. I have LabVIEW project experience and got certificate from National Instruments. I am looking for any type of job relating to my course.
    My E-mail: [email protected]
    My CV:
    Attachments:
    CV.doc ‏40 KB

    I like the optical bay caddy idea, as I barely use my optical drive anyway and it has some issues. The NewModeUS caddy seems a tad expensive for what it is, but it doesn't seem like there are any other options to choose from. I think I would probably just get an external USB optical drive to replace the internal optical drive completely.
    So, NewModeUS caddy, and how's this for a HDD?  One possible issue; I've read that some people have had issues with a 7200 RPM drive not working correctly when used as a secondary drive. A fluke, I hope?
    I've looked at the generic disk setup guidelines, and I'm wondering how much of a performance boost I would get from getting a 3rd drive (using eSATA). Is it worth going all in with that, or is getting even just a second drive going to help out significantly? The external option I've come up with: docking station (thanks John T Smith), and HDD (recommended on the forum)
    The Cineform neoscene looks useful, but I'm not sure I'm prepared to spend $130 on what is essentially a file converter. Thoughts on how much that would actually affect performance?
    Thanks for everyone's help so far, there's been more helpful suggestions than I'm allowed to mark, it looks like .

  • [svn:fx-trunk] 11548: MXFTEText. css now has a type selector for FTEDataGridItemRenderer that matches the one for DataGridItemRenderer in the MX default .css file.

    Revision: 11548
    Author:   [email protected]
    Date:     2009-11-06 16:35:27 -0800 (Fri, 06 Nov 2009)
    Log Message:
    MXFTEText.css now has a type selector for FTEDataGridItemRenderer that matches the one for DataGridItemRenderer in the MX default.css file. Both set paddingLeft to 5.
    QE notes: None
    Doc notes: None
    Bugs: SDK_22741
    Reviewer: Alex
    Tests run: ant checkintests
    Is noteworthy for integration: No
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/MXFTEText.css
        flex/sdk/trunk/frameworks/spark-manifest.xml

    AN UPDATE ON MY ISSUE:
    It appears to be limited to Dreamweaver. When I upload the files to my server and use BrowserLab or Microsoft SuperPreview the pages are rendering properly in all versions of IE. It's only broken when viewing in Design view within Dreamweaver or when using BrowserLab from within Dreamweaver. So at least I know my website works, which is a huge relief, but does anyone have any idea why Design view would complete ignore my styles? It's very annoying.

  • [svn:fx-trunk] 5029: Extending the mxmlc warning to apply to any application that uses a type selector (i.e.

    Revision: 5029
    Author: [email protected]
    Date: 2009-02-20 16:10:37 -0800 (Fri, 20 Feb 2009)
    Log Message:
    Extending the mxmlc warning to apply to any application that uses a type selector (i.e. not a universal selector) in the subject when the
    QE: If we could create a negative test cases for the warning that'd be great.
    Doc: Not yet, this will be captured in the Advanced CSS spec.
    Checkintests: Pass
    mustella: Advanced CSS, Button, MenuBar all Pass
    Reviewer: For Paul.
    Bugs:
    SDK-19272 - [Advanced CSS] Pseudo selectors shouldn't be allowed in mxml components
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-19272
    Modified Paths:
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/css/StylesContainer.java

    Thanks for the crash log  It looks like you have AIR 3.2 installed.  Could you try updating to 3.3 and generate another log?
    http://get.adobe.com/air

  • I am facing error while running Quickpay in Fusion payroll that "The input value Periodicity is missing for element type KGOC_Unpaid_Absence_Amount. Enter a valid input value". Any idea?

    I am facing error while running Quickpay in Fusion payroll that "The input value Periodicity is missing for element type KGOC_Unpaid_Absence_Amount. Enter a valid input value". Any idea?

    This is most probably because the Periodicity input value has been configured as "Required" and no value has been input for it.
    Please enter a value and try to re-run Quick Pay.

  • HT1752 I have an old iMac (the rounded type with monitor).  I need a new keyboard and mouse.  Will any work?  thanks for any help!

    I have an old iMac for 2002....it's the rounded type that has an attached monitor.  The software is way outdated (OS X 10) and I only really use now to access 3,000 plus songs and old video of the family.  Both the keyboard and mouse no longer work.  Am I able to use any keyboard/mouse and plug in using USB?  Thanks for any help!

    Most any USB mouse or keyboard should work. Borrow one if you can and just plug it in.
    If the USB circuits are at fault then you can access via Firewire Target Mode with another Mac in order to get at the files.
    http://support.apple.com/kb/HT1661
    Another alternative would be to remove the hard drive and use a USB adapter to access it as an external  drive.
    http://eshop.macsales.com/item/NewerTech/U3NVSPATA/

  • The system could not create any outputs for mv type 561

    Hi,
    I tried to print out a goods receipt others in MIGO and i received "The system could not create any outputs" when i tick on output control. I tried to follow the steps in How to print the material document in MB1C movement 561 I stuck at step 4 where i cannot find MvT 561. Please help
    Chk your setting as below to get GR print out.
    . Maintain the Printer Name in MM->Inv Mgmt and Phy Inv->Print Control-> Gen Settings-> Printer Setting Enter the local printer where you want to print your Goods posting document
    2. Ensure that in MM->Inv Mgmt and Phy Inv->Print Control->Gen Settings->Item Print Indicator, 1 stands for Matl Doc print out
    3. In MM->Inv Mgmt and Phy Inv->Print Control->Gen Settings->Print Version, maintain Print Version 2
    4. In MM->Inv Mgmt and Phy Inv->Print Control->Maintain Print Indicator for Goods Receipt/GI/Transfer Posting Documents
    Here for Particular mvt type 101,201,121,311,313,501,521,561 etcu2026 Maintain the Print item as 1--Material document printout
    5. In MM->Inv Mgmt and Phy Inv->Output Determination->Maintain Output Types, for the Output types WE01, WE02 and WE03, ensure the following--
    Select the particular Output type then goto Details
    a. Default Values: Dispatch Time is 3 or 4 as per reqmt. and Transmission medium is 1
    b. Print Parameter is 7
    6. In MM->Inv Mgmt and Phy Inv->Output Determination->Printer Det->Printer Determination by Plant/Str Loc , Maintain the Output device for all your Plants
    7. Go to MN21, for Tr Type WE, Print Version 3, maintain Print Item as 1.
    Now the settings are ready for Printing Material doc
    8. While doing MIGO, ensure that in General Tab, you get "3 Collective Slip" beside the Print Indicator and you tick mark the field.
    9. Now depending on the setting in 5a, the Matl doc is printed. If it is 3, you have to print it using MB90. If it is 4, it is printed immediately.

    issue is resolved

Maybe you are looking for