Inefficient string constructor - Scala rules - Semmle [PDF]

String(String) constructor. Since Strings are immutable, the allocated object is functionally indistinguishable from the

3 downloads 19 Views 30KB Size

Recommend Stories


Manualul inginerului constructor pdf
Courage doesn't always roar. Sometimes courage is the quiet voice at the end of the day saying, "I will

PdF Scala Cookbook
And you? When will you begin that long journey into yourself? Rumi

Scala Sockelleisten Scala Skirts
You often feel tired, not because you've done too much, but because you've done too little of what sparks

Unraveling yields inefficient matchings
Live as if you were to die tomorrow. Learn as if you were to live forever. Mahatma Gandhi

Code Cube Constructor
So many books, so little time. Frank Zappa

padre(STRING,STRING)
I cannot do all the good that the world needs, but the world needs all the good that I can do. Jana

Rules [PDF]
Aug 23, 2016 - Gayrimenkul Tasimacilik Pazarlama. Ithalat Ihracat ve Ticaret Ltd. Sirketi), and their seven associates (Luqman. Yasin Yunus Shgragi, Yunus Luqman. Yasin Shgragi, Abd Al Hakim Luqman. Jasim Muhammad, Muhammad 'ulwan. Al-Shawi, Ala al-S

Beaufort Scala
Come let us be friends for once. Let us make life easy on us. Let us be loved ones and lovers. The earth

Argh Rules Rules PDF format
Don't be satisfied with stories, how things have gone with others. Unfold your own myth. Rumi

Unraveling yields inefficient matchings
Just as there is no loss of basic energy in the universe, so no thought or action is without its effects,

Idea Transcript


Semmle 1.15

Pages / … / Inefficient code

Inefficient string constructor Created by Documentation team, last modified by Documentation team on Dec 12, 2016

Category: Maintainability > Inefficient code Description: Finds code that uses the java.lang.String(String) constructor. Since Strings are immutable, the allocated object is functionally indistinguishable from the argument, thus it is more memoryefficient to use the argument directly whenever possible. The String class is immutable; there is no way to change the string which it represents. As a result, there is rarely a need to copy a String object or construct a new instance based on an existing string.

Example def sayHello(world: String) { val hello = new String("Hello ") // BAD val message = new String(hello + world) // BAD println(new String(message)) // BAD } Recommendation Remove the new expression and instead use the argument to the string. For example, replace new String(message) by simply message.

References J. Bloch. Item 5: Avoid creating unnecessary objects. Effective Java (second edition). Addison-Wesley, 2008. Java API Documentation: String(java.lang.String)

maintainability Copyright © 2018 Semmle Ltd

inefficient-code

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.