In my previous years of development in C ++, I know that this convention has always initialized your variables with something.
I passed this convention with me in Java and really any other programming language that I use.
I use IntelliJ IDEA, and I am completely satisfied with this, and usually follow his programming instructions and warnings, however I received this warning:
public String getText(By by) { String text = null; // Variable `text` initializer `null` is redundant WebElement ele = findElement(by); highlightIfDemoMode(ele); String tagName = ele.getTagName(); if (tagName.equals("input") || tagName.equals("select")) // For field elements, the text is actually held in values, not the text. text = ele.getAttribute("value"); else text = ele.getText(); return text; }
Now, obviously, in Java,
String text; // is the *exact* same thing as.. String text = null;
Given that IntelliJ is very good at the following programming conventions, should I ignore this convention so as not to initialize my variables like this in Java? I feel this is a lot cleaner, but if the Java conventions tell me that, I won't.
Can someone tell me if it is better to practice for initialization or just conclude that it is null
source share