Java 5.0  Generics

Hi Guys ,
Been playing around with Generics and have been confused with them.
I have a generic CRUDAction :
public abstract class CRUDAction<T, U, F> extends PageBean implements Preparable {
protected U primaryKey;
     * @return the primaryKey
     public U getPrimaryKey() {
          return this.primaryKey;
     * @param primaryKey the primaryKey to set
     public void setPrimaryKey(U primaryKey) {
          this.primaryKey = primaryKey;
I'm using Struts2 and when the param interceptor runs it sets primaryKey with the submitted value.
Everyting is fine So far.
I create a new action based on this abstract with real types :
public class UserAction extends CRUDAction<User,Integer,UserFilter> {}
What I thought would happen was that setPrimaryKey(U primaryKey) --> setPrimaryKey(Integer primaryKey) ..
but I don't know why when I debug, struts2 is able to set String object through the setPrimaryKey method.
Am I doing something wrong ?

Seems like Struts 2 don't support generics (I never used struts).
In class file, method setPrimaryKey in UserAction have signature setPrimaryKey(Object), but not setPrimaryKey(Integer) This method is inherited from parent, where its argument is "erased" to Object during compilation. Information about actual type arguments (that argument for setPrimaryKey should be Integer) is avaliable via reflection, but application or library (struts2) should be aware of it.

Similar Messages

  • BUG: error rebuilding SQLJ files along other java files with generic

    I have done a rebuild on a package containing some SQLJ files, and (consistently) got the following error:
    C:\TeleMessage\trunk\src\telemessage\db\impl\dbAdmin.sqlj
        Error(44,18): Java Parsing. Encountered: <
        Expected: <IDENTIFIER> ...; "[" ...; The error at the cursor in the given file is not possible, since there was no '<' there, and besides - if I non-aggresively changed the file, e.g. narrowed imports, changed whitespace or added comments - the error remained in the same location.
    I went and done a search using regex in the package, for a line starting with 17 chars followed by a '<'.
    I found it in one of the normal JAVA files (not-SQLJ), at line 44 (surprise!) - in a Java 5 generics declaration, e.g. Map<String,Integer>. the 18th character was indeed the '<'.
    I'm guessing that the SQLJ translator (accidentally?) parses non-SQLJ files.
    If this cannot be fixed, it is really bad - it is one thing that JDeveloper cannot support Java 5 language features because of its dependancy in the SQLJ translator (which is not known to be upgraded until version 11g if at all), but the inability to compile SQLJ files in a project containing other non-SQLJ java files with Java 5 features is hard.
    I could only workaround this by rebuilding SQLJ files one at a time!
    I also have another type of error, when rebuilding the same project in a higher-level pacakge (root or "Application Sources"):
    C:\TeleMessage\trunk\src\dbtools\CallbackNumberFiller.sqlj
        Error(24,8): Missing semicolon.
        Error(24,8): Unbalanced curly braces.Again, the specified file could not be the one to blame - the location of the error is in the middle of the public modified keyword in a method declaration; nothing is neither missing nor unbalanced.
    This appears to be different, as it pops in the log near the end of the build process, when the JSPs are being built, specfically during the time the message log fills with "writing <...>" lines (after "translating <...>" and "compiling <...>".
    I can consistently reproduce both cases - please advise how I can help you find out what causes this.
    Regards,
    Yaniv Kunda

    First of all, this bug not JDeveloper's problem, but the SQLJ team's.
    You can read more posts about this:
    Re: BUG: Cannot translate SQLJ files with Java5 generics code
    Re: How to use SQLJ with Java 1.4 and 1.5?
    Re: SQLJ discontinued??
    And if we're at it, this is strange - I can't seem to find the oracle doc you quoted...
    SQLJ 11g? The latest release is a part of JPublisher 10.2 available from
    http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
    I also didn't find anything on google on 11g, nor about the part number you specified.
    Didn't find any Java 1.5 supporting SQLJ translators from other vendors as well.
    Do you have any link to this statement?
    But if we examine this bug again, the problem involves JDeveloper passing Java 5 featured JAVA files to the SQLJ translator.
    Isn't there a way to instruct the translator to use CLASS files compiled by a normal Java 5 compiler, instead of trying to compile the files itself?
    Regards,
    Yaniv Kunda

  • The Java Tutorials : Lesson Generics Question and Answers

    Hello,
    I've just finished reading the Generics Lesson from the Java Tutorials,
    http://java.sun.com/docs/books/tutorial/java/generics/index.html
    and was hoping to see the answers in the Question and Answer section at the end of the tutorial, but the link doesn't seem to be working.
    Could someone please grade my answers?
    The question is (copied from the Java Tutorials):
    1. Consider the following classes:
        public class AnimalHouse<E> {
            private E animal;
            public void setAnimal(E x) {
                animal = x;
            public E getAnimal() {
                return animal;
        public class Animal{
        public class Cat extends Animal {
        public class Dog extends Animal {
        }For the following code snippets, identify whether the code:
    * fails to compile,
    * compiles with a warning,
    * generates an error at runtime, or
    * none of the above (compiles and runs without problem.)
    a. AnimalHouse<Animal> house = new AnimalHouse<Cat>();
    b. AnimalHouse<Dog> house = new AnimalHouse<Animal>();
    c. AnimalHouse<?> house = new AnimalHouse<Cat>();
    house.setAnimal(new Cat());
    d. AnimalHouse house = new AnimalHouse();
    house.setAnimal(new Dog());
    My answers are:
    a. fails to compile
    b. fails to compile
    c. compiles and runs without problem
    d. compiles with a warning
    I realize that I could re-read the tutorial, but aside from learning about Generics, I'm also trying to gauge how well I absorb new information, the first time I read it, so I would appreciate if someone could tell me if my answers are correct. Explanations for incorrect answers would also be appreciated.
    Thanks

    Hi,
    as far as I understand it, and am able to explain, creating
    new AnimalHouse<Cat>();has the knowledge (at compiletime) about the generic type Cat.
    But as soon as this is assigned to
    AnimalHouse<?> house = new AnimalHouse<Cat>();the variable house, this knowledge is lost for the variable house. So you have house which does not know the underlying generic type used. Then, there are either two options:
    - allow adding anything via the set...-method
    - do not allow adding/setting anything at all
    In the first case, you would create the problem of being able to potentially add instances of types that do not have any relation to the originally used type Cat - which will cause problems (imagine setting a Car instance instead of a Cat instance and lateron expecting to retrieve something that should be a Cat but is a Car...).
    So, the only safe option is the second one.
    Weird to explain, but maybe there are better explanations around...
    Bye.

  • [ANN] Java IDE with generic type support

    Hello all!
    We are proud to announce that we have just released version 5.0 of our Java IDE CodeGuide.
    CodeGuide 5.0 offers full support for generic types as defined in JSR 14. Features are:
    - Fast incremental on-the-fly compilation
    - On-the-fly error checking of the whole project
    - Code completion
    - Usage search
    - Refactoring (like Renaming, Class moving, etc.)
    - and more...
    A 30-day trial can be downloaded from our web page at
    http://www.omnicore.com
    Any feedback regarding JSR 14 support is much appreciated.
    Best regards,
    Dennis Strein
    Omnicore Software

    I wrote a class MultiMap<K, V> extends Map<K, Set<V>>
        // Various constructors, methods, fields.
        public Set<V> get(K key)
            // Implementation
    } It compiles fine with the Sun reference compiler, but a friend tells me that CodeGuide 5.0 build 504 complains "There already is another method with the same erasure." It could be that CodeGuide is correct and Sun wrong, because I can see that there might be issues with overriding the get(Object) method with a get(K), but I thought I'd mention it.

  • Generics Java 5

    Just started using Java 5 and generics with kodo JDO 3.3.3 and in one of my
    classes (Army) used:
    private Set<Corps> corps = new HashSet<Corps>();
    When I tried to make the mapping I got an error dialog that just said "Kodo
    Error" (nothing else) and a warning message:
    WARNING: Collection/array field "model.units.Army.corps" has an unknown or
    unsupported element type; reverting to a BLOB mapping.
    It did not create the mapping file.

    Hi Dashi,
    How are you building the mapping? Do you get a stack trace in any log
    files? Finally, does this work if you run mappingtool from the command line?
    -Patrick
    Dashi wrote:
    Just started using Java 5 and generics with kodo JDO 3.3.3 and in one of my
    classes (Army) used:
    private Set<Corps> corps = new HashSet<Corps>();
    When I tried to make the mapping I got an error dialog that just said "Kodo
    Error" (nothing else) and a warning message:
    WARNING: Collection/array field "model.units.Army.corps" has an unknown or
    unsupported element type; reverting to a BLOB mapping.
    It did not create the mapping file.

  • Java Integration

    To me one of the most appealing aspects of JavaFX is it's integration with Java and being built on the Java Platform.
    There is lots of Swing engineers out there and lots of legacy code that can be given a new/modern "skin" using JavaFX - forget this bouncing ball mini-app crap....
    But thats were all the focus seems to be as if a "Sun app store" will be the future of JavaFX ...
    Its frurstrating as all us in the enterprise seem to be left behind somewhat (no first order FX Table yet - and not even in 1.3 (still listed as post 1.3) so we continue to wait ... while work on bouncing balls continue ;-)
    Anyway FX rant over... I am wondering if any work will be done to make working with Java backends a bit simpler ? Specificallly I have a large java backend that needs a new face - it was designed in such a way that the swing layer can be removed and FX added in..
    However my API has lots of the following:
    List<String> getListBlah()...
    i.e. lots of Generics... but FX script does not have any generic support and from what i hear its not planned...
    What is the best way to work with say Java6 latest features (Generics etc) in JavaFX (a java5 based scripting platform)
    -A-

    First, java 5 and java 6 have generics …
    JavaFX doesn’t have generics but have sequences.
    So, to use a list with generics in Javafx, you must translate it to a javaFX sequence
    For example:
    Java class
    public class MyTestService {
                public List<String> getListString(){
                ArrayList<String> list = new ArrayList<String>();
                list.add("String 1");
                list.add("String 2");
                list.add("String 3");
                return list;
    JavaFx class
    var myListString:String[];
    var myTestService:MyTestService = MyTestService{};
    myListString = (myTestService.getListString()).toArray(myListString);
    Stage {
        title: "Application title"
        scene: Scene {
            width: 250
            height: 150
            content: [
                    ListView {
                        width:100
                        height:125
                        items: bind myListString
    }Patrick Champion
    [http://paddyweblog.blogspot.com/]

  • Event handling in java

    Can we write a generic event listener which is activated on any event ?
    for example: instead of activating an event listener on clicking a butoon in should be activated on any mouse click...

    "Java" is too generic. I assume you mean Swing; you might as well be talking about JavaFX here. Your requirement is a bit odd and very much conflicting in any case. There is no such thing as a generic event listener, there are specific listeners for specific events.
    In stead of asking how to technically implement something, why don't you explain what you want to functionally achieve?

  • Java Doesn't Recognize Something That Exists?

    I'm writing an XML checker for a homework assignment. I'm using a stack which uses a double linked list which uses nodes with a generic data type.
    I ran into a problem after testing the program for the first time. I got a NullPointerException error at the instance where I tried to add a new node to the head. After a little digging I found out that apparently Java doesn't remember that I set the successor of "head" to be "tail". I've already spent 20 minutes going over the code that sets the tail as head's successor but I just can't see what I did wrong.
    Exception in thread "main" java.lang.NullPointerException
         at DLLNode.setNext(DLLNode.java:59)
         at DLLNode.<init>(DLLNode.java:17)
         at DLL.<init>(DLL.java:20)
         at Stack.<init>(Stack.java:11)
         at ParseTokens.<init>(ParseTokens.java:9)
         at Driver.main(Driver.java:16)The program is already too long to post here and broken up into multiple classes, so I will only post the important stuff. Note: Token is just a Record class that keeps two Strings, type and tagName for the xml tag to store.
    DLLNode.java //node with generic datatype T
         private T data;
         private DLLNode<T> successor;
         private DLLNode<T> predecessor;
         public DLLNode(T d, DLLNode<T> next, DLLNode<T> prev) {
              this.setNodeData(d);
              this.setNext(next); //line 17
              this.setPrev(prev);
           public T getNodeData() {
                return this.data;
           public void setNodeData(T newData) {
                this.data = newData;
           public DLLNode<T> getNext() {
                return this.successor;
           public void setNext(DLLNode<T> newNext) {
                this.successor = newNext;
                System.out.println(newNext.toString()); //zeroed in on the problem being here; throws NullPointerException; line 59
           public DLLNode<T> getPrev() {
                return this.predecessor;
           public void setPrev(DLLNode<T> newPrev) {
                this.predecessor = newPrev;
           }DLL.java //manages the DLLNode objects
         private DLLNode<T> head;
         private DLLNode<T> tail;
    //other vars
         public DLL() {
              this.setHead(new DLLNode<T>(null, tail, null)); //problem is probably here; after this, java doesn't see tail as head's successor; //line 20
              this.setTail(new DLLNode<T>(null, null, head));
              this.setSize(0);
           public void setHead(DLLNode<T> value) {
                this.head = value;
           public void setTail(DLLNode<T> value) {
                this.tail = value;
         public boolean addAtHead(T dllData) {
              DLLNode<T> newNode = new DLLNode<T>(dllData, this.head.getNext(), this.head);          
              this.getHead().getNext().setPrev(newNode); //original NullPointerException thrown here at the first instance of this method being used
              this.getHead().setNext(newNode);
              this.setSize(this.getSize() + 1);
              return ((newNode != null) && (newNode.getNext() != null) &&
                        (newNode.getPrev() != null));
         }Stack.java //manages a DLL object as a stack
         private DLL<T> dll;
         public Stack() {
              dll = new DLL<T>(); //line 11
              this.setSize(dll.getSize());
           public void push(T data) {
                dll.addAtHead(data); //original NullPointerException at first instance of push() being used
           }ParseTokens.java //class to actually go through the xml and list what it finds
         private Stack<Token> stack;
         public ParseTokens() {
              stack = new Stack<Token>(); //original error; line 9
         }Driver.java //main
    ParseTokens parse = new ParseTokens();//line 16Thank you for any help.
    Edited by: WhoCares357 on Feb 16, 2010 5:10 PM
    Edited by: WhoCares357 on Feb 16, 2010 5:17 PM

    A user on another forum h(http://preview.tinyurl.com/yjqx4a9) helped me find the problem. I had to create the head and tail first and then point them at each other. Thanks for all the help here.
    @flounder Even though I've already solved my problem I am still confused by what you're saying. The double linked list I created has two placeholders so that I don't have to worry about how many nodes are included. To connect my new node I start at the head and point at whatever is connected to the head (whether it is the tail or another node) to set the successor and predecessor for the new node. I then break the old connections (from the head to the old node after it) and connect them to the new node. I don't see a problem in this, but I am most likely not understanding your concern.
    I don't really want to let this go, because there might be a problem in my code that I don't see right now.
    @AndrewThompson64 I'll use that the next time I have a problem. Thanks.

  • EclipseLink + JPA + Generic Entity + SINGLE_TABLE Inheritance

    I was wondering if it's possible in JPA to define a generic entity like in my case PropertyBase<T> and derive concrete entity classes like ShortProperty and StringProperty and use them with the SINGLE_TABLE inheritance mode? If I try to commit newly created ElementModel instances (see ElementModelTest) over the EntityManager I always get an NumberFormatException that "value" can't be properly converted to a Short. Strangely enough if I define all classes below as inner static classes of my test case class "ElementModelTest" this seems to work. Any ideas what I need to change to make this work?
    I'm using EclipseLink eclipselink-2.6.0.v20131019-ef98e5d.
    public abstract class PersistableObject
        implements Serializable {
        private static final long serialVersionUID = 1L;
        private String id = UUID.randomUUID().toString();
        private Long version;
        public PersistableObject() {
               this(serialVersionUID);
        public PersistableObject(final Long paramVersion) {
              version = paramVersion;
        public String getId() {
    return id;
        public void setId(final String paramId) {
      id = paramId;
        public Long getVersion() {
    return version;
        public void setVersion(final Long paramVersion) {
      version = paramVersion;
        public String toString() {
      return this.getClass().getName() + "[id=" + id + "]";
    public abstract class PropertyBase<T> extends PersistableObject {
        private static final long serialVersionUID = 1L;
        private String name;
        private T value;
        public PropertyBase() {
    this(serialVersionUID);
        public PropertyBase(final Long paramVersion) {
      this(paramVersion, null);
        public PropertyBase(final Long paramVersion, final String paramName) {
      this(paramVersion, paramName, null);
        public PropertyBase(final Long paramVersion, final String paramName, final T paramValue) {
      super(paramVersion);
      name = paramName;
      value = paramValue;
        public String getName() {
    return name;
        public void setName(final String paramName) {
      name = paramName;
        public T getValue() {
    return value;
        public void setValue(final T paramValue) {
      value = paramValue;
    public class ShortProperty extends PropertyBase<Short> {
        private static final long serialVersionUID = 1L;
        public ShortProperty() {
    this(null, null);
        public ShortProperty(final String paramName) {
      this(paramName, null);
        public ShortProperty(final String paramName, final Short paramValue) {
      super(serialVersionUID, paramName, paramValue);
    public class StringProperty extends PropertyBase<String> {
        private static final long serialVersionUID = 1L;
        protected StringProperty() {
    this(null, null);
        public StringProperty(final String paramName) {
      this(paramName, null);
        public StringProperty(final String paramName, final String paramValue) {
      super(serialVersionUID, paramName, paramValue);
    public class ElementModel extends PersistableObject {
        private static final long serialVersionUID = 1L;
        private StringProperty name = new StringProperty("name");
        private ShortProperty number = new ShortProperty("number");
        public ElementModel() {
    this(serialVersionUID);
        public ElementModel(final Long paramVersion) {
      super(paramVersion);
        public String getName() {
      return name.getValue();
        public void setName(final String paramName) {
      name.setValue(paramName);
        public Short getNumber() {
      return number.getValue();
        public void setNumber(final Short paramNumber) {
      number.setValue(paramNumber);
    <?xml version="1.0" encoding="UTF-8" ?>
    <entity-mappings version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd">
    <mapped-superclass
      class="PersistableObject">
      <attributes>
      <id name="id">
      <column name="id" />
      </id>
      <version name="version" access="PROPERTY">
      <column name="version" />
      </version>
      </attributes>
    </mapped-superclass>
    <entity class="PropertyBase">
      <table name="PropertyBase" />
      <inheritance />
      <discriminator-column name="type"/>
      <attributes>
      <basic name="name">
      <column name="name" />
      </basic>
      <basic name="value">
      <column name="value" />
      </basic>
      </attributes>
    </entity>
    <entity class="StringProperty">
      <discriminator-value>StringProperty</discriminator-value>
    </entity>
    <entity class="ShortProperty">
      <discriminator-value>ShortProperty</discriminator-value>
    </entity>
    <entity class="ElementModel">
      <table name="ElementModel" />
      <inheritance />
      <discriminator-column name="type"/>
      <attributes>
      <one-to-one name="name">
      <join-column name="name" referenced-column-name="id" />
      <cascade>
      <cascade-all />
      </cascade>
      </one-to-one>
      <one-to-one name="number">
      <join-column name="number" referenced-column-name="id" />
      <cascade>
      <cascade-all />
      </cascade>
      </one-to-one>
      </attributes>
    </entity>
    </entity-mappings>
    public class ElementModelTest extends ModelTest<ElementModel> {
        public ElementModelTest() {
      super(ElementModel.class);
        @Test
        @SuppressWarnings("unchecked")
        public void testSQLPersistence() {
      final String PERSISTENCE_UNIT_NAME = getClass().getPackage().getName();
      new File("res/db/test/" + PERSISTENCE_UNIT_NAME + ".sqlite").delete();
      EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
      EntityManager em = factory.createEntityManager();
      Query q = em.createQuery("select m from ElementModel m");
      List<ElementModel> modelList = q.getResultList();
      int originalSize = modelList.size();
      for (ElementModel model : modelList) {
          System.out.println("name: " + model.getName());
      System.out.println("size before insert: " + modelList.size());
      em.getTransaction().begin();
      for (int i = 0; i < 10; ++i) {
          ElementModel device = new ElementModel();
          device.setName("ElementModel: " + i);
        device.setNumber((short) i);
          em.persist(device);
      em.getTransaction().commit();
      modelList = q.getResultList();
      System.out.println("size after insert: " + modelList.size());
      assertTrue(modelList.size() == (originalSize + 10));
      em.close();

    This was answered in a cross post here java - EclipseLink + JPA + Generic Entity + SINGLE_TABLE Inheritance - Stack Overflow
    Short answer: No, it shouldn't work as the underlying database field type would be constant.  So either the Short or the String would have problems converting to the database type if they both mapped to the same table field. 

  • Generics bounds behaviour

    Hi,
    I encountered a problem while using generics.
    Here is the code that dont compile using javac (but does using eclipse compiler).
    public interface MyThing {
    public interface MyObject<S extends MyThing>{
         public S getMyThing();
    public class MyObjectHandler{
         private MyObject<?> c;
         public MyObject<?> getHandled(){
              return c;
    public static void main(String[] args) {
         MyObjectHandler h = new MyObjectHandler();
         MyThing s = h.getHandled().getMyThing();
    }However, if i change prototypes of MyObjectHandler#getHandled() to this:
    private MyObject<? extends MyThing> c;
    public MyObject<? extends MyThing> getHandled(){
         return c;
    }Or if i turn MyThing to a class instead of interface...
    Can someone explains me what is happening there, and why does eclipse compiler allow this and not javac ?

    I'm still trying to understand it...
    I'm missing something, i guess...
    Here is the bytecode:
    Compiled from "MyObjectHandler.java"
    public class generics.MyObjectHandler extends java.lang.Object{
    public generics.MyObjectHandler();
      Code:
       0:   aload_0
       1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
       4:   return
    public generics.MyObject getHandled();
      Code:
       0:   aload_0
       1:   getfield        #2; //Field c:Lgenerics/MyObject;
       4:   areturn
    Compiled from "MyObject.java"
    public interface generics.MyObject{
    public abstract generics.MyThing getMyThing();
    }The worst is that i can't found any differences into the decompiled bytecode between this cases:
    Not Working
    public class MyObjectHandler{
         private MyObject<?> c;
         public MyObject<?> getHandled(){
              return c;
    Working
    public class MyObjectHandler{
         private MyObject<? extends MyThing> c;
         public MyObject<? extends MyThing> getHandled(){
              return c;
    }

  • Help on upgrading this code to Java 5

    Hi guys,
    I was trying to upgrading the following code to comply with Java 5 using generics, but I failed. Hope somebody here can help me out of this.
    This is the original code:
    import java.util.*;
    public class TestJava5{
        public static void main(String [] args){
            TestJava5 t = new TestJava5();
            Collection strs = t.getAll(String.class);
            for(Iterator i = strs.iterator(); i.hasNext();){
                System.out.println(i.next());
        private Collection getAll(Class c){
            Collection rs = new ArrayList ();
            if(String.class.equals(c)){
                rs.add("str1");
                rs.add("str2");
            }else if(StringBuffer.class.equals(c)){
                rs.add(new StringBuffer("buffer1"));
                rs.add(new StringBuffer("buffer2"));
            return rs;
    }and this is the code I tried to use generics, but obviously, I cannot add a String or StringBuffer into a Collection<T>.
    import java.util.*;
    public class TestJava5{
        public static void main(String [] args){
            TestJava5 t = new TestJava5();
            Collection<String> strs = t.getAll(String.class);
            for(String str:strs){
                System.out.println(str);
        private <T> Collection<T> getAll(Class<T> c){
            Collection<T> rs = new ArrayList<T>();
            if(String.class.equals(c)){
                rs.add("str1");
                rs.add("str2");
            }else if(URI.class.equals(c)){
                rs.add(new StringBuffer("buffer1"));
                rs.add(new StringBuffer("buffer2"));
            return rs;
    }

    Actually, now I've looked at it, it's even worse than that!
    You create a collection with type T, but this type is not fixed at compile type (by definition, obviously). So when you come to add something to the collection (either a String or a StringBuffer), the compiler cannot guarantee that your collection is of the correct type.
    This code is really on a hiding to nothing, I would suggest. But... the following should relieve your immediate compilation problems. However, it is likely to cause further problems when trying to use the returned collection:
      private <T> Collection<?> getAll2(Class<T> c) {
        if (String.class.equals(c)) {
          Collection<String> rs = new ArrayList<String>();
          rs.add("str1");
          rs.add("str2");
          return rs;
        } else if (URI.class.equals(c)) {
          Collection<StringBuffer> rs = new ArrayList<StringBuffer>();
          rs.add(new StringBuffer("buffer1"));
          rs.add(new StringBuffer("buffer2"));
          return rs;
        } else {
          return null;  // or something else like new ArrayList<Object>()
      }

  • New in Generics

    Hi Guys,
    Sorry if my post irritates you or seems annoying. But I'm just a beginner learning Java Generics and I really have difficulties understanding Generic Methods and Interfaces (not Generic Class though). I read the Anglika's FAQ on Java Generics, however, it's stated that it's not meant for beginner.
    I wonder whether this is any tutorial suitable for beginner in Generics and I really done my Google search. I don't really understand what is being taught in Java 1.6 Tutorial.
    Really need your helps in elaboration and examples not found in Java 1.6 Tutorial.
    I hope to understand this path and move on to the next section in the tutorials.
    Thanks and appreciate any kind of help.
    Regards,
    Jenson

    Have a look at this tutorial:
    http://java.sun.com/j2se/1.5/pdf/generics-tutorial.
    pdf
    Hi Prometheuzz,
    I did read through but I find it hard to digest and to I have difficulties in grabbing the concepts and ideas behind Generics, now I'm reading Deitel's Java: How to Program on Generics, hopefully I will get to understand better from there. Then I will proceed on to the Sun Java tutorial on Generics, then go through the exercises and move on to the next section in the tutorial. I wish I can finish the whole tutorial soon without getting stuck on too many areas >.<"

  • Java in Industry?

    I have a question for the Software Engineers here.
    I am an electrical engineer who writes a lot of C for embedded systems.  I can hold my own in C++, it is my language of choice when I want to create a GUI application (usually to interact with hardware and the embedded systems I have designed)  I use Qt, Gtkmm, and I've been playing with wxWidgets.  Cross platform development is important to me.
    I have learned Python, bit have not done anything for production with it (With the exception of a Django driven web site).  I have successfully built PyGtk and PtQt experimental applications.
    Given the current economy, I want to keep my skills relevant -- So here is the question:  I have avoided Java. At first because it was interpreted, then because of Microsoft's embrace, extend, extinguish attempt, now I worry about Oracle.   Is my head up and locked, or should I put some effort into learning Java?   Where is it heading? (I perceive it is mostly used in Behind-the-firewall Enterprise Applications by IT groups -- Not of interest to me)  Is it used in end user applications?  Is it still used to drive web applications or has it been surpassed by things like PHP?

    I have worked both in the public sector and the private. Believe me, when I say this, Java is here to stay at least for the foreseeable future. The amount of applications that are built and also the fact that so many critical applications use Java (for the companies that I have worked on), switching to anything else is highly unlikely.
    The management at the private sector company had millions of meetings just to upgrade to Java 5 from Java 4 simply because they didn't want anything to "break" on their watch. Do you think they will just go from Java to something else overnight? That would mean re-creating all of the functionality from scratch.
    There are many things I dislike about Java as well -- Generics is the prime example. I think its a shitty way to develop and "backward compatibility" was the reason they did what they did. It sucks, so I try not to use it at all. But Java is what I do, so I can't say that its all bad.
    Good thing is that there is Scala (functional programming language similar to Ruby in some regards) which works with Java bytecode, and I am honing my skills in that. So I can develop in Scala and the management won't know the difference. (as long as I just include the scala.jar  in the app )
    Last edited by Inxsible (2010-07-07 19:42:03)

  • Why do I get a ClassCastException?

    Hello!
    I'm playing around with hibernate, axis2 and Weblogic 8.1.6 and I got I really tricky problem.
    My Weblogic 8.1.6 got consist of 3 servers.
    1 Adminserver (myserver)
    1 Managedserver (ejbserver)
    1 Managedserver (webserviceserver)
    My play_around_example is built around a database called names in a mysql-databas.
    To access data I got a package called nameshibernate.jar, that works fine used from an standalone application called namesjavaapplication.jar.
    (namesjavaapplication->nameshibernate->database)
    I also got an ejb in a packaged called namesejb.jar that uses the nameshibernate.jar. The namesejb.jar is deployed under "Ejb Modules" and the target is "ejbserver". If I call the ejb from my standalone application called namesjavaapplication.jar it works fine.
    (namesjavaapplication->namesejb->nameshibernate->database)
    I also got an webserviceapplication that uses axis2 in a aar-file called nameswebservice.aar. This application uses the namesejb.jar. The Axis2-server is deployed in the server under "Web Application Modules" and the target is "webserviceserver". In this Axis2-server the nameswebservice.aar is deployed. This i supposed to work like:
    (namesjavaapplication->nameswebservice->namesejb->nameshibernate->database)
    If I call the webservice from my standalone application called namesjavaapplication.jar I get a calsscast exception:
    java.lang.ClassCastException: Cannot narrow remote object to namesejb.client.NameManagerEJBHome
    I really can not find out the problem since it works fine if I go directly to the ejb like:
    (namesjavaapplication->namesejb->nameshibernate->database)
    Below is the method inside my standalone application that calls the ejb directly.
    This is the code that works:
    (namesjavaapplication->namesejb->nameshibernate->database)
         public void getNamesEJB() throws Exception
              try
                   System.out.println("getNamesEJB start");
                   Context context = getWebLogicInitialContext();
                   Object object = context.lookup("namesejb/client/NameManagerEJBHome");
                   System.out.println("\t1: " + object.getClass().getName());
                   Class c = Class.forName("namesejb.client.NameManagerEJBHome");
                   System.out.println("\t2: " + c.getName());
                   System.out.println("\t3: " + NameManagerEJBHome.class.getName());
                   System.out.println("\t4: " + (object instanceof NameManagerEJBHome));
                   System.out.println("\tjava.class.version: " + System.getProperty("java.class.version"));
                   System.out.println("\tjava.class.path: " + System.getProperty("java.class.path"));
                   System.out.println("\tjava.library.path: " + System.getProperty("java.library.path"));
                   System.out.println("\tjava.compiler: " + System.getProperty("java.compiler"));
                   System.out.println("\tjava.ext.dirs: " + System.getProperty("java.ext.dirs"));
                   System.out.println("\tuser.dir: " + System.getProperty("user.dir"));
                   System.out.println("\tjava.home: " + System.getProperty("java.home"));
                   if(object instanceof namesejb.server.NameManagerSessionBean)
                        System.out.println("\t"+ ((namesejb.server.NameManagerSessionBean)object).getSerialVersionUID() );
                   else
                        System.out.println("\tNOT instanceof NameManagerSessionBean");
                   NameManagerEJBHome nameManagerEJBHome = (NameManagerEJBHome)PortableRemoteObject.narrow(object, NameManagerEJBHome.class);
                   NameManangerEJBObject nameManangerEJBObject = nameManagerEJBHome.create();
         String nameString = "";
                   List names = nameManangerEJBObject.getNames();
         for (int i = 0; i < names.size(); i++)
         Name theName = (Name) names.get(i);
         nameString = nameString + "\n" + theName.getName();
         textAreaEJB.setText(nameString);
              catch(RemoteException e)
                   e.printStackTrace();
              catch(NamingException e)
                   e.printStackTrace();
              catch(Exception e)
                   e.printStackTrace();
    From this I get this output:
    getNamesEJB start
    1: namesejb.server.NameManagerSessionBean_o0oo54_HomeImpl_816_WLStub
    2: namesejb.client.NameManagerEJBHome
    3: namesejb.client.NameManagerEJBHome
    4: true
    java.class.version: 50.0
    java.class.path: namesjavaapplication.jar
    java.library.path: /home/fredrik/Applications/Java/Java_ee_sdk_5-04/jd k/jre/lib/i386/server:/home/fredrik/Applications/Java/Java_ee_sdk_5-04 /jdk/jre/lib/i386:/home/fredrik/Applications/Java/Java_ee_sdk_5-04/jdk /jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
    java.compiler: null
    java.ext.dirs: /home/fredrik/Applications/Java/Java_ee_sdk_5-04/jdk/jr e/lib/ext:/usr/java/packages/lib/ext
    user.dir: /home/fredrik/eclipse_workspace/namesjavaapplication
    java.home: /home/fredrik/Applications/Java/Java_ee_sdk_5-04/jdk/jre
    NOT instanceof NameManagerSessionBean
    Below is my methods inside the ejb:
         public void ejbCreate()
              try
                   Class c = Class.forName("namesejb.client.NameManagerEJBHome");
                   System.out.println("1: " + c.getName());
                   System.out.println("2: " + NameManagerEJBHome.class.getName());
                   System.out.println("java.class.version: " + System.getProperty("java.class.version"));
                   System.out.println("java.class.path: " + System.getProperty("java.class.path"));
                   System.out.println("java.library.path: " + System.getProperty("java.library.path"));
                   System.out.println("java.compiler: " + System.getProperty("java.compiler"));
                   System.out.println("java.ext.dirs: " + System.getProperty("java.ext.dirs"));
                   System.out.println("user.dir: " + System.getProperty("user.dir"));
              catch(Exception e)
                   System.out.println(e.getMessage());
                   e.printStackTrace();
         public ArrayList getNames() throws Exception {
              Class c = Class.forName("namesejb.client.NameManagerEJBHome");
              System.out.println("4 " + c.getName());
              NameManager nameManager = new NameManager();
              return nameManager.getNames();
    From these methods I get this output from the ejbserver:
    1: namesejb.client.NameManagerEJBHome
    2: namesejb.client.NameManagerEJBHome
    java.class.version: 48.0
    java.class.path:/home/fredrik/Applications/bea/jrockit81sp6_142_10/lib/tools.jar:/home/fredrik/Applications/bea/weblogic81/server/lib/weblogic_sp.jar:/home/fredrik/Applications/bea/weblogic81/server/lib/weblogic.jar::/home/fredrik/Applications/bea/weblogic81/common/eval/pointbase/lib/pbserver44.jar:/home/fredrik/Applications/bea/weblogic81/common/eval/pointbase/lib/pbclient44.jar:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/rt.jar:/home/fredrik/Applications/bea/weblogic81/server/lib/webservices.jr:
    java.library.path:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/i386/jrockit:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/i386:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/../lib/i386:/home/fredrik/Applications/bea/weblogic81/server/lib/linux/i686:/home/fredrik/Applications/bea/weblogic81/server/lib/linux/i686/oci920_8
    java.compiler: null
    java.ext.dirs: /home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/ext
    user.dir: /home/fredrik/Applications/bea/user_projects/domains/mydomain
    4 namesejb.client.NameManagerEJBHome
    THIS WORKS FINE
    Below is the method inside my webservice that calls the ejb directly.
    This is the code that throws the Exception:
    (namesjavaapplication->nameswebservice->namesejb->nameshibernate->database)
         public String getNamesWSEJB() throws Exception
              String errorMessage = "Error: ";
              try
                   System.out.println("getNamesWSEJB start");
                   Context context = getWebLogicInitialContext();
                   Object object = context.lookup("namesejb/client/NameManagerEJBHome");
                   System.out.println("\t1: " + object.getClass().getName());
                   Class c = Class.forName("namesejb.client.NameManagerEJBHome");
                   System.out.println("\t2: " + c.getName());
                   System.out.println("\t3: " + NameManagerEJBHome.class.getName());
                   System.out.println("\t4: " + (object instanceof NameManagerEJBHome));
                   System.out.println("\tjava.class.version: " + System.getProperty("java.class.version"));
                   System.out.println("\tjava.class.path: " + System.getProperty("java.class.path"));
                   System.out.println("\tjava.library.path: " + System.getProperty("java.library.path"));
                   System.out.println("\tjava.compiler: " + System.getProperty("java.compiler"));
                   System.out.println("\tjava.ext.dirs: " + System.getProperty("java.ext.dirs"));
                   System.out.println("\tuser.dir: " + System.getProperty("user.dir"));
                   System.out.println("java.home: " + System.getProperty("java.home"));
                   if(object instanceof namesejb.server.NameManagerSessionBean)
                        System.out.println("\t"+ ((namesejb.server.NameManagerSessionBean)object).getSerialVersionUID() );
                   else
                        System.out.println("\tNOT instanceof NameManagerSessionBean");
                   NameManagerEJBHome nameManagerEJBHome = (NameManagerEJBHome)PortableRemoteObject.narrow(object, NameManagerEJBHome.class);
                   NameManangerEJBObject nameManangerEJBObject = nameManagerEJBHome.create();
         String nameString = "";
                   List names = nameManangerEJBObject.getNames();
                   for (int i = 0; i < names.size(); i++)
                        Name theName = (Name) names.get(i);
                        nameString = nameString + "\n" + theName.getName();
                   return nameString;
              catch(RemoteException e)
                   errorMessage = errorMessage + e.getMessage();
                   e.printStackTrace();
              catch(NamingException e)
                   errorMessage = errorMessage + e.getMessage();
                   e.printStackTrace();
              catch(Exception e)
                   errorMessage = errorMessage + e.getMessage();
                   e.printStackTrace();
              return errorMessage;
    1: namesejb.server.NameManagerSessionBean_o0oo54_HomeImpl_816_WLStub
    2: namesejb.client.NameManagerEJBHome
    3: namesejb.client.NameManagerEJBHome
    4: false
    java.class.version: 48.0
    java.class.path:/home/fredrik/Applications/axis2-1.3/lib/jalopy-1.5rc3.jar:/home/fredrik/Applications/bea/jrockit81sp6_142_10/lib/tools.jar:/home/fredrik/Applications/bea/weblogic81/server/lib/weblogic_sp.jar:/home/fredrik/Applications/bea/weblogic81/server/lib/weblogic.jar::/home/fredrik/Applications/bea/weblogic81/common/eval/pointbase/lib/pbserver44.jar:/home/fredrik/Applications/bea/weblogic81/common/eval/pointbase/lib/pbclient44.jar:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/rt.jar:/home/fredrik/Applications/bea/weblogic81/server/lib/webservices.jar:
    java.library.path: /home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/i386/jrockit:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/i386:/home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/../lib/i386:/home/fredrik/Applications/bea/weblogic81/server/lib/linux/i686:/home/fredrik/Applications/bea/weblogic81/server/lib/linux/i686/oci920_8
    java.compiler: null
    java.ext.dirs: /home/fredrik/Applications/bea/jrockit81sp6_142_10/jre/lib/ext
    user.dir: /home/fredrik/Applications/bea/user_projects/domains/mydomain
         NOT instanceof NameManagerSessionBean
    java.lang.ClassCastException: Cannot narrow remote object to namesejb.client.NameManagerEJBHome
    at weblogic.iiop.PortableRemoteObjectDelegateImpl.narrow(PortableRemoteObjectDelegateImpl.java:242)
    at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
    at nameswebservices.NamesWebService.getNamesWSEJB(NamesWebService.java:49)
    at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
            at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
            at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:165)
            at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:98)
            at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
            at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:96)
            at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:145)
            at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
            at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:120)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
            at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1077)
            at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)
            at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:348)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:7047)
            at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
            at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
            at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3902)
            at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2773)
            at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
            at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
    I really can not find out what might be the problem since it works to call tje ejb from a standalone application.
    The "same" code executed from a webservice throws the exception.
    One strange thing that I notice is that from the standalone the java.class.version gets 50.0 and from the webserver it gets 48.0 But the standalone uses 1.6 when I run it and the Weblogic uses 1.4. (I do not think that weblogic can run with 1.6)
    Pretty long thread but I hope for some mercy!
    Best regards
    Fredrik                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hello Thok, this code is from a quistion in a studybook for preparation of the SCJP 5.0 exam.
    When i compile i get this warning:
    Shapes.java:13: warning: [unchecked] unchecked cast
    found   : java.util.ArrayList
    required: java.util.ArrayList<generics.Rectangle>
            ArrayList <Rectangle> c = (ArrayList<Rectangle>) b;
                                                             ^
    1 warningWhen running this line causes an exception:
                for ( Rectangle o : c){My questions are
    How do i re-write the code so that i will get an warning and exception free program?
    Tnx Auke

  • Pattern to suppress unchecked warnings at the line level

    Hi,
    As we migrate our APIs to Java 5 (exploiting generics in particular), we are hitting some cases in which we chose not to address the unchecked warnings. To make the code cleaner we thought about annotating methods with @SuppressWarnings("unchecked") but this has the major drawback of turning off all warnings (instead of just the very few we are comfortable leaving behind).
    A colleague of mine had a really interesting idea to solve this problem. It can be expressed by the class below:
    public final class Cast
      @SuppressWarnings("unchecked")
      public static <T> T uncheckedCast(Object object)
        return (T)object;
    }Now we are using this to suppress the specific unchecked warnings we want to ignore. If we decide to revisit these cases, we can just query the usages of the method above.
    Although this approach seems really clean to me, I would love to hear your option on it. Can you see any major problem that we are getting ourselves into?
    Thanks in advance,
    Marcelo

    I'm not sure why, but you cannot apply annotation to arbitrary lines. The lowest level of granularity is an assignment statement.
    The good news is that the @SuppressWarnings annotation can be applied at that level.
    So, whilst this won't work:
      @SuppressWarnings("unchecked")
      someMethodCall((T)obj);this, will:
      @SuppressWarnings("unchecked")
      T tObj = (T)obj;
      someMethodCall(tObj);

Maybe you are looking for

  • Problem installing Windows 8.1 on MBP

    Ok so I was having bluetooth issue in Windows 7, which is a different issue, so I decided to try Windows 8.1 Pro X64 Using boot camp I get to the part where Windows is asking where to install. I choose Drive 0 Partition 4: Boot Camp and format it. On

  • How to validate the file path when downloading.

    Hi How to validate the file path when downloading to Presentation or application Server.

  • HT2534 "none" does not appear as a credit card option?

    I follow the instructions on setting up an iTunes account without a credit card (so I can download album art) but the "none" does not appear as a card option after following the instruction to first download a free app.

  • Hp Photosmart E317 camera

    Hello all, We bought our granddaughter an HP Photosmart E-317 digital camera and we are having problems with it shutting itself off when ever it wants to .  Does any one know how to fix this problem or why it does it?  At first we thought it was tryi

  • Material transaction

    A material item can produce in a plant1 as well as purchase local or import .this material can send later to plant2 ,valuated and non valuated.(Free or for sales ).Plant 2 can buy it from other vendors and put it to manufacturing processes. Also ther