cast

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    cast

    Code:
     public static IBagResult cartesianProduct(IAbstractQueryResult resLeft, 
             IAbstractQueryResult  resRight){
          IBagResult  elements = null;
          List   resLeftL= new ArrayList();
          List   resRightL= new ArrayList();
    
             
         resRightL.add(resRight);
         
         resLeftL.add(resLeft);
     for(int i=0; i<=resLeftL.size(); i++){
                 
         for(int j=0; j<= resRightL.size(); j++)
         
         [B]{ Integer cP = resLeftL.get(i)*resRightL.get(j);[/B]         
             
             elements.addElements(cP);
                     
         }   
             }
     return elements;
    
     }
    Integer cP = resLeftL.get(i) *resRightL.get( j);

    i dont know how to cast it to multiply it
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    The way I see it, resLeft and resRight (the elements you're adding to the Lists resLeftL and resRightL respectively) aren't numbers so you can't multiply them. What value from them are you trying to multiply?

    Also, you should not use raw Lists. Rather than
    [code=java]List resLeftL = new ArrayList();
    List resRightL = new ArrayList();[/code] you should use
    [code=java]List<IAbstractQ ueryResult> resLeftL = new ArrayList<IAbst ractQueryResult >();
    List<IAbstractQ ueryResult> resRightL = new ArrayList<IAbst ractQueryResult >();[/code] That way the element type returned by resLeftL.get(i) will be known at compile time.

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      i want two integers passed as (IAbstractQuery Result resLeft,
      IAbstractQueryR esult resRigh)
      cast them to Integer

      where should i cast them

      Comment

      • oll3i
        Contributor
        • Mar 2007
        • 679

        #4
        Exception in thread "main" java.lang.Class CastException: s4409_s4409_pr2 .IntegerResult cannot be cast to java.lang.Integ er
        at s09_.QExecUtils .cartesianProdu ct(QExecUtils.j ava:42)
        at s09_s4409_pr2.( _pr2.java:38)
        Java Result: 1

        Comment

        • oll3i
          Contributor
          • Mar 2007
          • 679

          #5
          how to cast IntegerResult to Integer

          Comment

          • oll3i
            Contributor
            • Mar 2007
            • 679

            #6
            Code:
            public class IntegerResult implements IIntegerResult{
             Integer i =null;
            @Override
            public  Integer getValue(){ return i;} 
            
            public IntegerResult(Integer i){ 
                this.i=i;
            }
            
            }

            Comment

            • Nepomuk
              Recognized Expert Specialist
              • Aug 2007
              • 3111

              #7
              You don't cast it, you call the getValue() function on it. That will return an Integer.

              Comment

              Working...