Is there a way to unify type parameters ?

+[Accidentally posted in the Java Programming forum here: http://forum.java.sun.com/thread.jspa?threadID=5262928&tstart=0]+
The following code is pretty self contained. I will use some Haskell to explain the problem, cause it's easier (for me) to read.
For those foreign to Haskell, the basic syntax of these signatures is:
function_name :: ArgType1 -> ArgType2 -> .... -> ArgTypeN -> ReturnTypeWith list (or in this case ArrayList) arguments as:
[ArgTypeN]It starts off with the definition of:
BinaryFunction<T,U,X>With main method:
apply :: T -> U -> XThen is defined:
fold :: X -> [U] -> XAnd inside fold, apply is called such that X = T
apply :: X -> U -> XThis only compiles if the first argument to apply is cast to T, with the warning "BinaryFunction.java uses unchecked or unsafe operations."
My question is whether X can be unified with T manually at the call-site or in the definition of fold, in a safe way. Otherwise, I would like to know if it's acceptable to leave the cast in, since it's obviously ok.
Thanks. =)
package lib.functional;
import lib.functional.FunctionApplicationError;
import java.util.ArrayList;
public abstract class BinaryFunction<T,U,X>
     abstract public X apply(T t, U u) throws FunctionApplicationError;
     private X fold(X x, ArrayList<U> us)
            for (U u : us)
                 x = apply((T) x, u); // *************************
            return x;
}Edited by: Dorice on Feb 11, 2008 3:25 AM
Changed title... Hopefully this is clearer.

Dorice wrote:
It should be okay as long as I only use BinaryFunction<X, U, X>() when I need fold, right?If you only need X U X, why define T (or why define X)?
The main problem here is that, once you defined your instance, the generic types are defined. So, maybe ejp's advice would be a solution for your problem as you expect the X to be a T to define X extends T.
This would be different, if BinaryFunction was instantiated each time before invoking apply.
Oh yeah, I forgot to (re)ask, can I still play ball with the cast in place?What for? The cast will be no cast, as the warning says. It works accidentally at runtime in case X subclasses T. Thus, the type safety you define by Generics only is pretended and factually pointless.

Similar Messages

  • Is there a way to unify multiple Voice ISDN-BRI to single group?

    I'm just wondering is there a way to unify multiple BRI interfaces in signle than to include it in the dial-peer for easier call routing.
    Thanks in advance

    Absolutely, trunk-groups:
    int bri x/y
    trunk-group telco
    dial-peer voice 100 pots
    destination-pattern ...
    trunkgroup telco
    Then, under "trunk group telco" you can optionally configure translation-profiles, hunt schemes and other things. "show trunk group" will give you the status of all the circuits in there.
    Hope this helps, please rate post if it does!

  • Is there a way to control brush parameters by special layer mask or channel?

    Is there a way to control brush parameters by special layer mask or channel? Maybe there is some plug-in for mask controlled brushes? Or channel controlled brushes?

    You are not understanding how masks work.  If you look closely at the first six brush tip options in the brush panel, either of the first two will give you a fixed size stroke regardless of pen pressure
    To control the appearance, or masking of specific colours, you would use a Hue/Saturation adjustment layer, and use the RGB drop down to select the colour you want to affect.  Without know _exactly_ what you are trying to achieve, no one can do more than guess, but from what you have written so far, I suspect you are going to be out of luck.
    What tablet are you using?  And you did not answer my question about what version of Photoshop?   You need to be a _lot_ more specific about what you want to do if you want keep my fast failing interest in this thread.

  • Ok so my iPhone won't let me type. The only way I can use my phone is by first putting in an apple ID. Since I can't type I can't get passed this step to use my phone. Is there any way I can type on my computer or something for my iPhone?

    Is there a way I can type on my computer for my iPhone?

    It will only sync with new messages received after Mac's Messages is configured and running.
    It will not synced old messages.

  • Is there any way to edit Importing Parameters in BADI?

    Hi guys,
    Is there any way to edit the values of Importing Parameters in BADI? To be more specific, I need to edit plant in PR structure in IF_EX_IWO1_PREQ_BADI.
    Thanks.

    Hi sam,
    No it is not possible.
    Regards,
    Atish

  • Not connected to internet where my library is. When I import cds is there a way to manually type in track info?

    My Ipod library is on a computer not connected to internet. Is there a way to manually put track info from cds once they are imported?

    Right click - "Get Info", change the ID3 tag.  You can copy and paste album art too.

  • Is there any way to unify the columns view between playlists?

    When you add columns or resize columns it only effects whatever playlist you are in.
    Is there any way to make them all the same?

    When you create a new playlist, it will model the current column view of your (main music) library in list view.

  • Is there a way I can type in English but have it translate my words into another language?

    I speak english.  I want to be able to type the English words and have them translated into other languages.  Japanese kanji, katagana, hiragana in my specific case.  I tried using text input, but it just translates a letter at a time making my word a mix in English letters and Katagana characters. 

    seraph6496 wrote:
    I want to be able to type the English words and have them translated into other languages.
    Not now. Maybe in a few years or so. Or maybe never, if you stop to think about it.
    There are several free automatic translators on the web. You can find them by googling it. (Your Dashboard translator uses Systran's.)
    I tried using text input
    I assume you mean you enabled Kotoeri, the Japanese input method. This is for those who wish to type in Japanese. It's not a translating tool.

  • Is there a way to reset the parameters of all the system's native users and groups to their default settings?

    After the upgrade to 10.8.3 my console is streaming perpetually with hundreds of lines of what appears to be permissions denials.
    I've rebuilt permissions from my admin user, root, safeboot, an external virgin os install, and the recovery partition
    run disk utility multiple times
    safebooted multiple times
    rebuilt the directory structure via the latest build of Diskwarrior
    removed all peripherals
    reset PRAM
    reset SMC
    ran the Extended Hardware Test
    all drivers are up-to-date
    Used OnyX to hunt for corrupted preference files
    Used Onyx to clean every cache in the system
    Cleaned up the fonts via Font Book
    Rebuilt Launch Services
    Rebuilt dyld's shared cache
    Disabled Swap
    Disabled Time Machine Local Backups
    I'm running a 2011 MBP Quad i7 17" 2.3GHz 750gig internal 7200rpm with 16gig of ram 1600x1200 display
    OSX 10.8.3 with dev kit

    For what it's worth, this is the exact same set of ACL's that get "fixed" every single time i run the permissions repair:
    Started verify/repair permissions on disk1s2 Flux
    ACL found but not expected on "private/etc/apache2/users"
    Repaired "private/etc/apache2/users"
    ACL found but not expected on "private/etc/postfix/aliases"
    Repaired "private/etc/postfix/aliases"
    ACL found but not expected on "private/etc/postfix/main.cf"
    Repaired "private/etc/postfix/main.cf"
    ACL found but not expected on "private/etc/postfix/master.cf"
    Repaired "private/etc/postfix/master.cf"
    ACL found but not expected on "private/etc/profile"
    Repaired "private/etc/profile"
    ACL found but not expected on "Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
    Repaired "Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
    ACL found but not expected on "Library/Preferences/com.apple.alf.plist"
    Repaired "Library/Preferences/com.apple.alf.plist"
    ACL found but not expected on "System/Library/LaunchDaemons/org.postfix.master.plist"
    Repaired "System/Library/LaunchDaemons/org.postfix.master.plist"
    ACL found but not expected on "Users/Shared"
    Repaired "Users/Shared"
    ACL found but not expected on "private/etc/named.conf"
    Repaired "private/etc/named.conf"
    ACL found but not expected on "private/var/root/Library"
    Repaired "private/var/root/Library"
    ACL found but not expected on "private/var/root/Library/Preferences"
    Repaired "private/var/root/Library/Preferences"
    ACL found but not expected on "System/Library/Keychains/X509Anchors"
    Repaired "System/Library/Keychains/X509Anchors"
    ACL found but not expected on "private/etc/hostconfig"
    Repaired "private/etc/hostconfig"
    ACL found but not expected on "private/etc/shells"
    Repaired "private/etc/shells"
    ACL found but not expected on "private/etc/ssh_config"
    Repaired "private/etc/ssh_config"
    ACL found but not expected on "private/etc/sshd_config"
    Repaired "private/etc/sshd_config"
    ACL found but not expected on "private/var/db/launchd.db/com.apple.launchd"
    Repaired "private/var/db/launchd.db/com.apple.launchd"
    ACL found but not expected on "private/var/yp/binding"
    Repaired "private/var/yp/binding"
    Finished verify/repair permissions on disk1s2 Flux

  • Is there a way to have type in a text field that would disappear when you filled in the field?

    I'm trying to create a form in Acrobat X that has instructions in the text field (like account number) for instance...that would disappear when the customer starts to fill in their number or information? I've seen examples of this but cannot figure out how to make it work.

    You can use a custom Format script like:
    if (!event.value) event.value = "Instructional text goes here";

  • How to get instance of Class with its type parameters

    Hi,
    Have any of you folks been dealing with generics long enough to show me how this should be written? Or point me to the answer (I have searched as well as I could).
    I boiled down my situation to the included sample code, which is long only because of the inserted comments. And while boiling I accidentally came across a surprise solution (a bug?), but would obviously prefer a smoother solution.
    My Questions (referred to in the code comments):
    #1. Is there a way to get my parameterized type (classarg) without resorting to using the bogus (proto) object?
    #2. Can anyone understand why the "C" and "D" attempts are different? (All I did was use an intermediate variable????) Is this a bug?
    Thanks so much for any input.
    /Mel
    class GenericWeird
       /* a generic class -- just an example */
       static class CompoundObject<T1,T2>
          CompoundObject(T1 primaryObject, T2 secondaryObject)
       /* another generic class -- its main point is that its constr requires its type class */
       static class TypedThing<ValueType>
          TypedThing(Class<ValueType> valuetypeclass)
       // here I just try to create a couple of TypedThings
       public static void main(String[] args)
          // take it for granted that I need to instantiate these two objects:
          TypedThing<String>                        stringTypedThing = null;
          TypedThing<CompoundObject<String,String>> stringstringTypedThing = null;
          // To instantiate stringTypedThing is easy...
          stringTypedThing = new TypedThing<String>(String.class);
          // ...but to instantiate stringstringTypedThing is more difficult to call the constructor
          Class<CompoundObject<String,String>> classarg = null;
          // classarg has got to be declared to this type
          //    otherwise there will rightfully be compiler error about the constructor call below
          // This method body illustrates my questions
          classarg = exploringHowToGetTheArg();
          // the constructor call
          stringstringTypedThing = new TypedThing<CompoundObject<String,String>>(classarg);
       } // end main method
       // try compiling this method with only one of A,B,C,D sections uncommented at a time
       private static Class<CompoundObject<String,String>> exploringHowToGetTheArg()
          Class<CompoundObject<String,String>> classarg = null;
          /* Exhibit A: */
      ////     classarg = CompoundObject.class;
             results in compiler error "incompatible types"
             found   : java.lang.Class<GenericWeird.CompoundObject>
             required: java.lang.Class<GenericWeird.CompoundObject<java.lang.String,java.lang.String>>
                   classarg = CompoundObject.class;
                                            ^
             I understand this.  But how to get the type information?
          /* It's obnoxious, but it looks like I will have to construct a temporary
              prototype instance of type
                 CompoundObject<String,String>
              in order to get an instance of
                 Class<CompoundObject<String,String>>
              (see my Question #1) */
          CompoundObject<String,String> proto = new CompoundObject<String,String>("foo", "fum");
          /* Exhibit B: */
      ////     classarg = proto.getClass();
             results in compiler error: "incompatible types"
             found   : java.lang.Class<capture of ? extends GenericWeird.CompoundObject>
             required: java.lang.Class<GenericWeird.CompoundObject<java.lang.String,java.lang.String>>
                   classarg = proto.getClass();
                                            ^
          /* Exhibit C: */
      ////     classarg = proto.getClass().asSubclass(proto.getClass());
             results in compiler error: "incompatible types"
             found   : java.lang.Class<capture of ? extends capture of ? extends GenericWeird.CompoundObject>
             required: java.lang.Class<GenericWeird.CompoundObject<java.lang.String,java.lang.String>>
                   classarg = proto.getClass().asSubclass(proto.getClass());
                                                         ^
          /* Exhibit D: (notice the similarity to C!): */
      ////     Class tmp1 = proto.getClass();
      ////     classarg = tmp1.asSubclass(tmp1);
          /* It compiles (see my Question #2) */
          return classarg;
       } // end method exploringHowToGetTheArg()
    } // end class GenericWeird

    Thanks so much, Bruce. (Oh my goodness, how would I have ever come up with that on my own?)
    So in summary
    This doesn't compile:
          classarg = (Class<CompoundObject<String,String>>)CompoundObject.class;but these do compile:
          classarg = (Class<CompoundObject<String,String>>)(Class)CompoundObject.class;or
          Class coclass = (Class)CompoundObject.class;
          classarg = (Class<CompoundObject<String,String>>)coclass;And this doesn't compile:
           classarg = proto.getClass().asSubclass(proto.getClass());but this does:
           Class tmp1 = proto.getClass();
           classarg = tmp1.asSubclass(tmp1);

  • Is there a way to jump to a letter in mail?

    This is something frustrating that I've been putting up with since I moved to Mail (from Eudora) a couple years ago and just never had the time to ask about it. I asked in an Apple store and the guy was like - what - oh . . .that is crappy . . .
    So when you're in your InBox (though any mailbox would apply) and you select 'From' from the header bar to view your emails by who they came from, is there a way to just type an 'A' to get to the beginning of the emails coming from all 'A' emails. It ***** cause lets say I have 300 emails in my inbox - (not uncommon on some days) and I click the 'From' and I'm down in the 'R's, I have to scroll up to find the 'who' I'm looking for. It's stupid because I used to be able to do that with Eudora.
    And - second question - if you can't do this, how or where do I submit a suggestion to Apple?

    I guess I could do that, but that is just extra clicks and mousing. It seems like you should be able to click the "from" column and then type "a" and it goes to the A's in the 'from' list. This type of character navigation works in all of Apples finder windows: Click on your Applications folder and then type 'pre' and it goes right to the 'Preview' application - no searching neccessary - why not the mail?
    And do you know where I would ask for a Feature Upgrade or Include suggestion? I'm just not finding it easily.
    Thanks.

  • Is there a way to create form fields to tab into and type and or drop down selection fields in pages as you can with microsoft word?

    is there a way to create form fields to tab into and type and or drop down selection fields in pages as you can with microsoft word?

    No

  • Is there a way to save a form, once filled out, as a different file type in Reader?

    I have Acrobat, my coworkers only have Reader. Company won't purchase Acrobat for the other employees.
    I built a form for my coworkers to fill out. We need them to be able to send the filled out form to clients, but we don't want the clients to be able to edit the forms.
    I understand people with only Reader can't flatten the document, or add a password, or save it as non editable. As I understand it, even with Acrobat I can't assign a password for Reader users to be able to edit or not edit a file (PLEASE correct me if I'm wrong on that one).
    Is there any way to save the PDF form once it's been filled out (in Reader) as a different file type? Even an image? The file we send to clients doesn't have to be a PDF. Just something that most people can open.
    I tried inserting the PDF into a word document (unreadably pixelated) and tried taking a snapshot of the entire page (resolution too low). I've tried downloading one of the free PDF writers and it apparently won't work with our network security (or something along those lines). I've tried using the pdf writer for Firefox on the form once it was filled out, and that won't work either because our network firewall seems to be blocking it and that's not something they are willing to take down.
    Any advice?

    The signature WILL work! I've just looked into it more, thank you so much for pointing me in that direction.
    I get it now, it locks the form fields in place after my coworker fills them in and signs it (as the very last step).
    I wish I would have asked on here a full day ago. Would have saved a lot of headache and Googling.
    Thanks again.

  • We had a MacBook Pro stolen from our home when we were out of town and I am pretty sure we never activated the LoJack type of function on it not sure if its called lojack but you get what I am saying is there any way we can activate such  hardware/app now

    to
    We had a MacBook Pro stolen from our home when we were out of town and I am pretty sure we never activated the LoJack type of function on it not sure if its called lojack but you get what I am saying is there any way we can activate such  hardware/app now so we can possibly recover our laptop? Any one who can point us in the right direction that would be great and we would be very grateful. Thanks So Much

    Lojack for laptops - if that is the product you purchased and installed, you will need to read the user manual or contact the manufacturer as it is 3rd party.  You did file a police report right?

Maybe you are looking for

  • How to create a certificate using keytool / terminal?

    I have problems with creating certificates using the terminal. I use the instructions below and typed in all the required information. When it asks me to type "yes" and confirm, the whole process just starts from the beginning over and over and I hav

  • No images in editing window, but there in Navigator

    I just installed Service Pack 2 in my Vista Ultimate 32bit operating system. After the install I opened PS, CS4 and at first every thing looked ok. I then opened an image file, it came up in RAW, I made initial adjustments, and clicked on open image.

  • Can I make a *smaller* base image for a mobileme gallery?

    So as near as I can tell, I cannot set the maximum size for an image in a mobileme gallery...is there a preset for that? I realize that I can disable downloading, but if I want a base image that is more "facebooky" in resolution, can I specify that?

  • Basic material regarding SD

    Hi Experts, I am an abap resource. I want to learn very basic concepts of SD. Can you please give me some basic material. Regards, krishan

  • JDBC Drivers in 11g R1 vs. R2

    Is there a major difference between JDBC drives of ORacle 11gR1 and R2?