difference between row2.state.equals('Arizona') vs 'Arizona'.equals(row2.state)

Highlighted
Six Stars

difference between row2.state.equals('Arizona') vs 'Arizona'.equals(row2.state)

Hello Team, 

Could help me explain the difference between 

row2.state.equals('Arizona') vs 'Arizona'.equals(row2.state)

in expresssion under tjoin inner join tab.


Accepted Solutions
Fifteen Stars TRF
Fifteen Stars

Re: difference between row2.state.equals('Arizona') vs 'Arizona'.equals(row2.state)

"Arizona".equals(row2.state) will never finish by a null pointer exception but row2.state.equals("Arizona") will fail if row2.state is null.


TRF

All Replies
Fifteen Stars TRF
Fifteen Stars

Re: difference between row2.state.equals('Arizona') vs 'Arizona'.equals(row2.state)

"Arizona".equals(row2.state) will never finish by a null pointer exception but row2.state.equals("Arizona") will fail if row2.state is null.


TRF
Six Stars

Re: difference between row2.state.equals('Arizona') vs 'Arizona'.equals(row2.state)

thanks TRF. 

Seven Stars

Re: difference between row2.state.equals('Arizona') vs 'Arizona'.equals(row2.state)

As TRF said, you should NEVER use the first one.

 

The second create a static String object, which prevent any exception, so you can do many operations like : !"".equals(row1.data)

The first syntax is a bad syntax and should be banned from all Java code you can ever find Smiley Happy

 

You can use that trick in many situations if you're not sure of the nullability of your String.

 

Example : row1.data+""      will never be null, even if "data" is an Integer Smiley Wink

Six Stars

Re: difference between row2.state.equals('Arizona') vs 'Arizona'.equals(row2.state)

Actually i was using this Arizona'.equals(row2.state) in tmap to only select rows with Arizona.

 

TMSSQLinput     -              tmap          -    MSSQLoupt

tmssqlinput (Lookup)  - above tmap

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog