Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

== operator problem

  Asked By: Diane    Date: Apr 21    Category: Java    Views: 914

I'm using SOAP with Tomcat and have tested a java example code which
subtracts two input parameters. Now I want to use a third input
parameter which should decide which function should be called. (The
subtract function or the addition function).

The problem is that when I use the 'equal to' operator (==) I get this
error message from the compiler:

CalcClient.java:23: operator == cannot be applied to
if( p3 == 1 )
CalcClient.java:25: operator == cannot be applied to
else if( p3 == 2 );
2 errors

My code looks like this:

import java.lang.*;
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;

public class CalcClient {

public static void main(String[] args) throws Exception {

URL url = new URL

Integer p1 = new Integer(args[0]);
Integer p2 = new Integer(args[1]);
Integer p3 = new Integer(args[3]);
// Build the call.
Call call = new Call();

if (p3 == 1)

if else (p3 == 2)

Did I forget something? If so, please tell me.
Could this problem have something to do with my classpaths or import



2 Answers Found

Answer #1    Answered By: Francis Riley     Answered On: Apr 21

You need to use if(p3.intValue() == 3) p3 is defined as an Integer
object not an int.

Answer #2    Answered By: Alan Palmer     Answered On: Apr 21

You cannot compare a primitive with an object, you
must turn the object into a primative.

if ( p3 == 1 )

turns into

if ( p3.intValue() == 1 )

Didn't find what you were looking for? Find more on == operator problem Or get search suggestion and latest updates.