Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the Java library source code so strangely indented?

I often rely on the JDK source code to understand how I should implement an interface, and I often find some very strange indentation style at use. For instance, in DefaultCellEditor.java:

public DefaultCellEditor(final JTextField textField) {
    editorComponent = textField;
this.clickCountToStart = 2;
    delegate = new EditorDelegate() {
        public void setValue(Object value) {
    textField.setText((value != null) ? value.toString() : "");
        }

    public Object getCellEditorValue() {
    return textField.getText();
    }
    };
textField.addActionListener(delegate);
}

I'm wondering if this is due to my IDE or not, since I find this kind of indentation quite strange and difficult to read.

like image 261
Aurelien Ribon Avatar asked Sep 14 '11 20:09

Aurelien Ribon


People also ask

What is indenting in Java?

An intent is to perform an action on the screen. It is mostly used to start activity, send broadcast receiver,start services and send message between two activities. There are two intents available in android as Implicit Intents and Explicit Intents. Here is a sample example to start new activity with old activity.

Are indentations important in Java?

Indentation. Perhaps the most important style rule you can learn is to indent properly. The compiler cares nothing about indentation, but if you indent well, you make your code so much easier to read, which means you'll make it easier to debug.


1 Answers

Sounds like a tab vs spaces issue. Try setting the tab width to 4 spaces (or 8 if it is 4).

Here is what I see when browsing the OpenJDK code for DefaultCellEditor online.

enter image description here

like image 170
Charles Goodwin Avatar answered Sep 18 '22 23:09

Charles Goodwin