[java]if(type_msg == "0200") 맞는 문법 아닙니까?

송효진의 이미지

이니시스 가상결제 모듈 때문에 자바를 만지게 되었습니다.

type_msg 변수에 String 으로 0200 이 들어오면 처리를 하도록 하려는데,

if(type_msg != "0200") {
    printDebug(type_msg);
}

하면, 0200 이 찍힙니다.

if 문이 false 되었다는건데요...

O 와 0 의 구분은 분명히 했으며

둘 다 String 인데요.

왜 비교가 안되는지 모르겠습니다.

어떤 이유가 있을까요?

Necromancer의 이미지

equals() 메소드 쓰지 않나요? (메소드 이름 맞나 =3=3==33)

if(!(type_msg.equals("0200"))) {
    printDebug(type_msg);
}

Written By the Black Knight of Destruction

nohmad의 이미지

송효진 wrote:
이니시스 가상결제 모듈 때문에 자바를 만지게 되었습니다.

type_msg 변수에 String 으로 0200 이 들어오면 처리를 하도록 하려는데,

if(type_msg != "0200") {
    printDebug(type_msg);
}

하면, 0200 이 찍힙니다.

if 문이 false 되었다는건데요...

O 와 0 의 구분은 분명히 했으며

둘 다 String 인데요.

왜 비교가 안되는지 모르겠습니다.

어떤 이유가 있을까요?

==은 객체(의 주소)를 비교하는 것이지 객체의 값을 비교하지는 않습니다. primitive type을 비교할 때에는 ==을 사용할 수 있지만, string은 객체입니다. equals()을 써야 합니다.

다크슈테펜의 이미지

자바에서 ==은 스트링클래스는 참조된 주소값을 비교하게 됩니다.즉 안에 있는 데이터를 비교하는게 아닙니다.만약 스트링의 값을 비교 하실려고 하신다면 equals을 사용하시는게 맞으실것 같습니다.

인생이란게 다 그런게 아니겠어요....? 뭘(?)
http://schutepen.egloos.com

송효진의 이미지

감사합니다.
해결 하였습니다.
그것 해결하고 나니
이니시스 가상계좌 서버가 PostgreSQL 에 붙지를 않더군요.

모듈명앞에 org. 가 붙게 되어 있는데, 기본적으로 안붙어 있어서,
매뉴얼 뒤져가며 겨우 해결 했네요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.