How to specify that a generic type should implement cloneable ?

Hi everybody,
I created a map type called StringMap as such
class StringMap<V>{
HashMap<String,V> map;
and now, I want to implement the method clone() in my StringMap, for that I would like to use the method V.clone()
but I get an error saying "The method clone() from type Object is not visible". This is logical since clone() is protected in Object class. So I believe a solution would be to specify that V implements the interface Cloneable(). This tried this:
class StringMap<V implements Cloneable>{
but it doesn't work.
Do you know a way to do it ?
Thanks

dubwai wrote:
r035198x wrote:
You can say <V extends Cloneable> instead.That still won't solve the root issue. The Cloneable interface has no methods and implementing it will not expose clone(). Cloneable is broken.Yep, I was hoping the OP would pick that up after that.

Similar Messages

  • I tried opening a pdf file and I set it to use always and firefox which did not work, I was wondering how to undo that and what I should use to open pdf files in the future?

    I was attempting to open a document from a frequently used site, I had never been on, on my new mac however. I attempted to open the pdf file and was given the option of which program to use to open it, I mistakenly clicked use always and firefox as the program with which to open pdf files. I do not know how to undo this or what I should do in the future to access the pdf files.

    Hi Melfour-
    Here is a Support article detailing how to work with your Firefox PDF preferences:
    [[Opening PDF files within Firefox]]
    Hope that helps.

  • Stipulate that a parameterised type must implement an interface

    Hi,
    1000 excuses if this has been asked before:
    I want to say "abstract class AbstractHolder<Y>" and also say "oh by the way, Y must implement interface Snodgrass"
    In other words I want to limit the kind of subelements which are held by the AbstractHolder so that an attempt to establish an AbstractHolder subclass which holds subelements which do not implement Snodgrass results in a compiler error.
    Of course you can put in an "instanceof" check in the constructor... but I think generics should enable you to say "abstract class AbstractHolder<Y implements Snodgrass>"... they don't appear to...
    Anything to be done?
    Thanks - MRodent

    <Y extends Whatever>This works if Y is an interface extending interface Whatever.
    It works if Y is a class extending class Whatever.
    It works if Y is a class implementng interface Whatever.
    I believe you can also say <Y extends A, B, C> or <Y extends A & B & C>
    http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html
    http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

  • How To: Use reflection to create instance of generic type?

    I would like to be able to use reflection to instantiate an instance of a generic type, but can't seem to avoid getting type safety warnings from the compiler. (I'm using Eclipse 3.1.1) Here is a trivial example: suppose I want to create an instance of a list of strings using reflection.
    My first guess was to write the following:
    Class cls = Class.forName("java.util.ArrayList<String>");
    List<String> myList = cls.newInstance();The call to Class.forName throws a ClassNotFoundException. OK, fine, so I tried this:
    Class cls = Class.forName("java.util.ArrayList");
    List<String> myList = cls.newInstance();Now the second line generates the warning "Type safety: The expression of type List needs unchecked conversion to conform to List<String>".
    If I change the second line to
    List<String> myList = (List<String>)cls.newInstance();then I get the compiler warning "Type safety: The cast from Object to List<String> is actually checking against the erased type List".
    This is a trivial example that illustrates my problem. What I am trying to do is to persist type-safe lists to an XML file, and then read them back in from XML into type-safe lists. When reading them back in, I don't know the type of the elements in the list until run time, so I need to use reflection to create an instance of a type-safe list.
    Is this erasure business prohibiting me from doing this? Or does the reflection API provide a way for me to specify at run time the type of the elements in the list? If so, I don't see it. Is my only recourse to simply ignore the type safety warnings?

    Harald,
    I appreciate all your help on this topic. I think we are close to putting this thing to rest, but I'd like to run one more thing by you.
    I tried something similar to your suggestion:public static <T> List<T> loadFromStorage(Class<T> clazz) {
        List<T> list = new ArrayList<T>();
        for ( ...whatever ...) {
           T obj = clazz.newInstance();
           // code to load from storage ...
           list.add(obj);
        return list;
    }And everything is fine except for one small gotcha. The argument to this method is a Class<T>, and what I read from my XML storage is the fully qualified name of my class(es). As you pointed out earlier, the Class.forName("Foo") method will return a Class<?> rather than a Class<Foo>. Therefore, I am still getting a compiler warning when attempting to produce the argument to pass to the loadFromStorage method.
    I was able to get around this problem and eliminate the compiler warning, but I'm not sure I like the way I did it. All of my persistent classes extend a common base class. So, I added a static Map to my base class:class Base
       private static Map<String, Class<? extends Base>> classMap = null;
       static
          Map<String, Class<? extends Base>> map = new TreeMap<String, Class<? extends Base>>();
          classMap = Collections.synchronizedMap(map);
       public static Class<? extends Base> getClass(String name)
          return classMap.get(name);
       protected static void putClass(Class<? extends Base> cls)
          classMap.put(cls.getName(), cls);
    }And added a static initializer to each of my persistent classes:class Foo extends Base
       static
          Base.putClass(Foo.class);
    }So now my persistence code can replace Class.forName("my.package.Foo") with Base.getClass("my.package.Foo"). Since Foo.class is of type Class<Foo>, this will give me the Class<Foo> I want instead of a Class<?>.
    Basically, it works and I have no compiler warnings, but it is unfortunate that I had to come up with my own mechanism to obtain a Class<Foo> object when my starting point was the string "my.package.Foo". I think that the JDK, in order to fully support reflection with generic types, should provide a standard API for doing this. I should not have to invent my own.
    Maybe it is there and I'm just not seeing it. Do you know of another way, using reflection, to get from a string "my.package.Foo" to a Class<Foo> object?
    Thanks again for your help,
    Gary

  • Creating instance of generic type

    Hi.
    Here is my class
    public class ManagerForm<M extends Stuff>{
    private Class<M>clazz;
    private M manager;
    public void setWorker(M manager){
    this.manager=manager;
    public M getWorker(){
    return this.manager;
    private final Class<M> getGenericClass() {
    Class<M> persistentClass = null;
    Type genericType = getClass().getGenericSuperclass();
    if (genericType instanceof ParameterizedType) {
    ParameterizedType pType = ((ParameterizedType) genericType);
    // obtaining first generic type class
    persistentClass = (Class<M>) pType.getActualTypeArguments()[0];
    return persistentClass;
    public ManagerForm(){
    this.clazz=getGenericClass();
    this.manager=this.clazz.newInstance();
    In default constructor I need to inicialize U instance this.user.
    I have an nullPointerException in line this.manager=this.clazz.newInstance();
    persistantClass is returned nullable because genericType is not instance of ParameterizedType.
    Could anybody say me what is wrong or propose other methods to create generic instance. I need help. Will be very appreciable.
    Thanks in advance.

    YoungWinston wrote:
    877715 wrote:
    Could anybody say me what is wrong or propose other methods to create generic instance. I need help. Will be very appreciable. I think you need to back up and explain exactly what you're trying to do here.
    It would appear that you're attempting to divine the actual type of a specific ManagerForm, but I'm not absolutely certain. Also, since you already specify the type as a field, why can't you just usemanager.getClass()? I suspect that all you'll get from getClass().getGenericSuperclass() is 'Stuff', but I have to admit I'm no expert on this.
    Far better to describe what you want than an implementation that plainly doesn't work.
    WinstonWell. I have class ManagerForm<M extends Stuff>. there is private field manager that have generic type M. And I need to instantinate manager in default constructor.
    I cant write
    public ManagerForm(){
    this.manager=new M();//will be compiler error
    Thats why exists a mechanism to get current generic type in runtyme through ParameterType.
    I have method getGenericClass that gets current class in runtime and then I create an instance of this class through <class>.newInstance(); And this is the standard way to instantinate generic type.
    I hoped line Type genericType = getClass().getGenericSuperclass(); of method returned ParameterizedType. But variable genericType cannot be casted to ParameterizedType. I don't know why. So I cannot get current generic param M and instantiate its.

  • If I go to the apple store to replace my ipad (screen craked) how long dos that take?

    if I go to the apple store to replace my ipad (screen craked) how long dos that take?

    They should replace the whole device, not just the screen. If they have it in stock, you will walk out with in in minutes. If you are not under warranty there is a charge.

  • Labview How to specify 1d array of clusters as data types for variant to data

    Hi, I'm new to labview. Can anyone tell me how to specify 1d array of clusters as data types for variant to data?

    First of all, you should be sure that there is such a data type within the variant; otherwise, you will run into errors.
    I recommend you to create the cluster and create a type definition from it. Then drop an array shell from the array palette and drop the cluster type into that array.
    Connect that constant to the data type input of the Variant To Data function.
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Difference between fully-specified data types. and generic types

    Hi,
    Can anyone tell me the difference between fully-specified data types and generic types.
    Thanks in advance.
    Regards,
    P.S.

    HI
    Generic table types
    INDEX TABLE
    For creating a generic table type with index access.
    ANY TABLE
    For creating a fully-generic table type.
    Data types defined using generic types can currently only be used for field symbols and for interface parameters in procedures . The generic type INDEX TABLEincludes standard tables and sorted tables. These are the two table types for which index access is allowed. You cannot pass hashed tables to field symbols or interface parameters defined in this way. The generic type ANY TABLE can represent any table. You can pass tables of all three types to field symbols and interface parameters defined in this way. However, these field symbols and parameters will then only allow operations that are possible for all tables, that is, index operations are not allowed.
    Fully-Specified Table Types
    STANDARD TABLE or TABLE
    For creating standard tables.
    SORTED TABLE
    For creating sorted tables.
    HASHED TABLE
    For creating hashed tables.
    Fully-specified table types determine how the system will access the entries in the table in key operations. It uses a linear search for standard tables, a binary search for sorted tables, and a search using a hash algorithm for hashed tables.
    Fully-specified table types determine how the system will access the entries in the table in key operations. It uses a linear search for standard tables, a binary search for sorted tables, and a search using a hash algorithm for hashed tables.
    see this link
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb366d358411d1829f0000e829fbfe/content.htm
    <b>Reward if usefull</b>

  • How to specify for a internal table field so that number of digits = 9

    In if condition how can i specify that
    if country = 'US'
    then the account number should be equal to 9 digits only.
    <removed_by_moderator>
    Edited by: Julius Bussche on Aug 6, 2008 1:41 PM

    You can set the internal table field to the biggest length possible, according to your requirements, and then work on something like the following. If the condition is met and you have to shorten the account number... try something similar to this:
    DATA e TYPE string VALUE 'Test string'.
    * I'm using 2 as an example here.
    SHIFT e BY 2 PLACES RIGHT CIRCULAR.
    SHIFT e BY 2 PLACES LEFT.
    WRITE :/, e.
    Avraham

  • How do I specify that I just want to print pg 1 to 2 not the rest of doc

    I'm new to apple and not sure how I specify which pages to
    print there doesn't seem to be a print preview in the sense I
    can specify and define what I want to print of a document.
    I found the 'grab' feature/crosshairs to locate on a portion of
    a page so I can print a portion of one page yet doesn't give me
    a range selector to specifically set it to certain no. of pages.
    Even if I have two page document I like to have the control
    to print one page so i can turn page over and print the 2nd
    page of a document versus having a bunch of one sided
    printed pages. Is there a double side print feature? Where do I
    find these settings in the Leopard 10.5 o/sys? Intuitively I'd think
    File print yet I wasn't able to come up with it as yet?

    When the print dialog box comes up, the default looks pretty small. However, there is a button that looks like a triangle next to the pull down menu where it says "Printer:". This will give you some more options, including being able to print pages in a specific range.
    Should say Pages: From # to #.

  • How to create an array with Generic type?

    Hi,
    I need to create a typed array T[] from an object array Object[]. This is due to legacy code integration with older collections.
    The method signature is simple:public static <T> T[] toTypedArray(Object[] objects)I tried using multiple implementations and go over them in the debugger. None of them create a typed collection as far as I can tell. The type is always Object[].
    A simple implementation is just to cast the array and return, however this is not so safe.
    What is interesting is that if I create ArrayList<String>, the debugger shows the type of the array in the list as String[].
    If I create ArrayList<T>, the class contains Object[] and not T[].
    I also triedT[] array = (T[]) Array.newInstance(T[].class.getComponentType(), objects.length);And a few other combinations. All work at runtime, create multiple compilation warnings, and none actually creates T[] array at runtime.
    Maybe I am missing something, but Array.newInstace(...) is supposed to create a typed array, and I cannot see any clean way to pass Class<T> into it.T[].class.getComponentType()Returns something based on object and not on T, and T.class is not possible.
    So is there anything really wrong here, or should I simply cast the array and live with the warnings?
    Any help appreciated!

    Ok. May be you could keep information about generic type in the your class:
    public class Util {
        public static <T> T[] toTypedArray(Class<T> cls, Object[] objects){
            int size = objects.length;
            T[] t = (T[]) java.lang.reflect.Array.newInstance(cls, size);
            System.arraycopy(objects, 0, t, 0, size);
            return t;
    public class Sample<T> {
        Class<T> cls;
        T[] array;
        public Sample(Class<T> cls) {
            this.cls = cls;
        public void setArray(Object[] objects){
            array = Util.toTypedArray(cls, objects);
        public T[] getArray(){
            return array;
        public static void main(String[] args) {
            Object[] objects = new Object[] { new LinkedList(), new ArrayList()};
            Sample<List> myClass = new  Sample<List>(List.class);
            myClass.setArray(objects);
            for(List elem: myClass.getArray()){
                System.out.println(elem.getClass().getName());
    }

  • Which file type should I use and how I use it?

    Hello!
    I need to create a file with some data that has been inserted manually.
    In this file, for example, there are:
    ProjectName1: string1, string7… string10, date1
    ProjectName2: string11, string15… string20, date2
    ProjectNamek: string 100, string 116 … string 140, date1
    I know only one thing: one of the strings.
    What I need to find in the file:
    I need to find the string at one of these rows and get its ProjectName and date.
    For example: if I have string15,
    I should find string15 in the file, and get its ProjectName and date:
    ProjectName2, date2
    Which file type should I use and how I use it? What is the best solution?
    Thanks!

    800512 wrote:
    I need to create a file with some data that has been inserted manually.
    In this file, for example, there are:
    ProjectName1: string1, string7… string10, date1In addition to Pandiya's advice, if the string is always in exactly the above format
    (ie:
    1. ProjectName always starts the line and ends with a ':'.
    2. The rest of the strings on the line are separated by ", " and will never contain ", "
    you might also want to have a look at String.split().
    Winston

  • I want to know what I need and then how to take a pdf form I created in word and add the blue boxes so that anyone can type into my form

    I want to know what I need and then how to take a pdf form I created in word and add the blue boxes so that anyone can type into my form

    Hey john@adobe,
    Could you please specify how exactly have you created your form.
    You might need to have Acrobat installed on your computer to convert a word document to PDF.
    Do you have Acrobat installed? If yes, what version? If no, then please try using the trial version of Acrobat DC (latest version) and access its features:
    Download Adobe Acrobat free trial | Acrobat Pro DC
    Also, let me know what kind of blue boxes are you talking about.
    If you want others to edit your PDF form, then you need to make it a fillable form by choosing 'Form Editing' option from Tools pane.
    Let me know more on this so that I can help you out.
    Regards,
    Anubha

  • How can I do a multiple record data merge, but specify that a specific text frame with variable data only merges on the first record?

    I'm doing a multiple record data merge, I have 2 frames both with variable data placed inside.
    I would like to specify that one of the text frames only merges once(first record) and the other frame multiple times for each record in the data file.
    Is it possible?
    I thought that perhaps if I place the text frame that must merge once on the master page, it would work.  But you are not allowed to place variable text on the master and on the document page.
    I'm going to try it through scripting next, but thought that perhaps there is an easier way that I'm not aware of.
    Thanks,
    Suzanne

    Suzanne,
    If you were trying to post a screen shot, you would need to return to the forum and post it using the "camera" icon at the top of the post editing windows.
    I use a plug-in from Em Software called InData. One of the benefits for what I do is there are no individual frames on a page to deal with post-merge. Individual frames are great for simple merges (address labels, post cards, etc.). But I typically do more other types of merges.
    That said, there is a drawback--one needs to come to an understanding of writing expressions that actually parse the incoming data. So in the spice price list example, that looks like:
    It's reasonably easy once one does it a few times. And it can be far more complicated. The above is from Em Software's samples that has been tweaked. The best thing I can recommend would be to download the trial and see for yourself. They are good at responding to specific questions if you get stumped.
    I imagine this all could be scripted somehow in ID. But I have no idea how and the plug-in just lets me keep working.
    Mike

  • If I buy a digital book in  EPUB size from a web site, how I may read it on my IPad? Specify that I didn't buy it from Apple Store.

    If I buy a digital book in  EPUB size from a web site, how I may read it on my IPad? Specify that I didn't buy it from Apple Store.

    First, epub has nothing to do with size, it is a file format that is popularly used for ebooks, but ebooks published in epub file formats vary greatly in file size.
    It will depend on where you buy it.  Many books are DRM locked (Digital Rights Management, a software lock).  If so, in order to load it into another companies reader or reader software, you need to use something like Adobe Digital Editions to "authorize" the book on the device.  Apple's iBook software does not work with ADE.
    If the book was DRM free, you should be able to read it in any ereader or ereader program that supports epub format.
    If the book is DRM locked to B&N, Amazon, Kobo or whichever seller you shopped from, then the simples thing is to download their free app for the iPad (they all make one, in fact they all make free apps for iPad, Android, Mac OS X and Windows).
    So the short answer is yes, you should be able to read any epub ebook file on an iPad, although not necessarily in iBook.
    So, books from
    Amazon - get the Kindle reader app
    B&N - get the Nook reader app
    Kobo - get the Kobo reader app
    non-DRM epubs can be read in iBook, Nook, Kobo, or Google Play

Maybe you are looking for

  • AUTODESK SUITE AND WINDOWS 8.1

    For the last one year, I have been using my Autocad and Inventor Pro with no problems in my two PC. Late June 2014, I was asked my Microsoft to update my OS to Windows 8.1. I did as I have been doing every time Microsoft tells me to update their stuf

  • Error in file-ro-idoc scenario

    Hi! I'm trying this scenario https://www.sdn.sap.com/irj/sdn/wiki?path=/display/profile/2007/05/11/fileToIDOC& And and have an error "Unable to convert the sender service MDM_to_CRM_BC to an ALE logical system". What maybe wrong in my scenario ?

  • 2106 WLC and 4 LWAPP (1252G)

    I have a 2106 WLC with 4 AP's (AIR-LAP1252AG-A-K9) One of the AP's (port 4) is only connecting at 10Mbps, not 100Mbps and I don't know why? All the ;ports are set on the controller to AUTO,  When I try to force that port to 100Mbps, the link drops. C

  • Airport card disappears in OS9?

    Hello all I just acquired a G4 cube.  It has 640MB RAM (more is on order) and a stock 16MB video card (got a new one on the way...) and the Airport card.  I just did a clean install of OS 9, and updated to 9.2.2.   The entire system, including the Ai

  • Object Change History

    Hi Friends, How to know when the objects like InfoObjects,Infocubes, DSO etc has changed and by whom it has been changed. Is there any table which can capture the Object creation and changed objects history in the system. Regards Revathi