vvavepacket
vvavepacket

Reputation: 1929

Object without new operator

PreparedStatement preparedStatement = connection.prepareStatement(sql);

preparedStatement.setString(1, "Gary");
preparedStatement.setString(2, "Larson");
preparedStatement.setLong  (3, 123);

'preparedStatement' is an object. But how can we call it as an object if it doesn't use the new operator?

Upvotes: 0

Views: 42

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198103

Sure it uses the new operator, it just uses new somewhere inside the implementation of prepareStatement. That's just calling another method that does the newing for you. That's actually a super common pattern called the factory pattern.

Upvotes: 4

Related Questions