Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 59
Registered: ‎05-06-2012
My Device: Blackberry torch 9850
My Carrier: Voila
Accepted Solution

java class name boolean give an unexpected result. PLEASE HELP

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /> <meta name="ProgId" content="Word.Document" /> <meta name="Generator" content="Microsoft Word 14" /> <meta name="Originator" content="Microsoft Word 14" />

Why the first if statement is not executed ?

 

Will appreciate a reponse.

Thank

 

 

 

package com.test.className;

 

 

public class classNameTest {

      

       public static void main(String args[]){

              new ProcessTest();

       }

}

 

class ProcessTest {

 

       public ProcessTest(){

              testit();

       }

 

       private void testit(){

              String cBug= new String(this.getClass().getName() );

              String MyClassNameIs= new String(this.getClass().getName() );

             

              if(cBug ==MyClassNameIs){

                     System.out.print("That work great. \n No problem.");

                     System.out.print(cBug + "\n");

                     System.out.print(MyClassNameIs + "\n");

              }else{

                     System.out.print("it's might a bug?\n");

                    

                     System.out.print("That do not work great. \nGot problem.\n");

                    

                     System.out.print(cBug + "\n");

                     System.out.print(MyClassNameIs + "\n");

              }

       }

}

 

Result from JVM :

it's might a bug?

That do not work great.

Got problem.

com.test.className.ProcessTest

com.test.className.ProcessTest

Developer
Posts: 239
Registered: ‎07-26-2010
My Device: Z10
My Carrier: Telkomsel

Re: java class name boolean give an unexpected result. PLEASE HELP

[ Edited ]

You should use equals() for string comparison.

 if(cBug.equals(MyClassNameIs))

 

Developer
Posts: 59
Registered: ‎05-06-2012
My Device: Blackberry torch 9850
My Carrier: Voila

Re: java class name boolean give an unexpected result. PLEASE HELP

You solved my issue anta40