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
Highlighted
Sixteen Stars
Sixteen 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

View solution in original post


All Replies
Highlighted
Sixteen Stars
Sixteen 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

View solution in original post

Highlighted
Six Stars

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

thanks TRF. 

Highlighted
Eight 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

Highlighted
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 GARTNER 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

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

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