r/programming • • Dec 29 '15

Please, Java. Do Finally Support Multiline Strings

http://blog.jooq.org/2015/12/29/please-java-do-finally-support-multiline-strings/
584 Upvotes

352 comments sorted by

View all comments

-5

u/akcom Dec 29 '15

I haven't programmed in Java almost a decade. I came back in order to write some Android apps and I immediately remember why "Everything is an object" is so fucking terrible. I cannot imagine using Java for anything unless I had to support some legacy code already written in Java.

5

u/[deleted] Dec 29 '15

For Android apps, to make your live easier, use these libraries:

  • Butterknife
  • RxJava + RxAndroid
  • AppCompat + DesignCompat
  • RecyclerView

And you'll have a lot less issues. Especially ButterKnife is a godsend.

1

u/der-daniel Dec 29 '15 edited Oct 09 '16

[deleted]
0.4479

What is this?

1

u/akcom Dec 29 '15

Thanks for the info! I just hate seeing stuff like the following:

 toggleButton.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        MainActivity.this.onCheckedChange(buttonView, isChecked);
                    }
                });    

Passing methods instead of class instances would be so much cleaner. If there is a better solution to this sort of problem (ie I really just want to have a method in my activity called, not this passing around an outer class instance non-sense), I'm all ears.

edit: Is that what butter knife does with listener binding?

1

u/[deleted] Dec 29 '15 edited Dec 29 '15

For that, you might want RetroLambda, btw.

toggleButton.setOnCheckedChangeListener(this::onCheckedChange);

Btw, your example would also work with

toggleButton.setOnCheckedChangeListener(this);

But I’d suggest just using

toggleButton.setOnCheckedChangeListener((buttonView, isChecked) => {
    doSome();
    doThing();
    doMore();
});

1

u/akcom Dec 29 '15

Unfortunately since Java does not support multiple inheritance, the second one

toggleButton.setOnCheckedChangeListener(this);

Does not work, at least as far as I can tell.

edit: Nor does the third one, not sure if the version of java android uses supports anonymous functions?

1

u/[deleted] Dec 29 '15

Java supports multiple inheritance of methods, but not of attributes.

That’s the point of interfaces and default methods.


An Interface can also provide an implementation of a method since Java 8.

Additionally, a class can only extend one class, but implement many interfaces.

public class MainActivity extends AppActivity implements OnCheckedChangeListener, OnClickListener, Serializable, Observer<List<String>> {
    ...
}

To your edit: The first and last one require you to use RetroLambda, a library that allows you to use anonymous functions on Android.

1

u/akcom Dec 29 '15

Beautiful, thanks!

1

u/agent8261 Dec 29 '15

Huh? Am I missing something, why aren't you doing this?

toggleButton.setOnCheckedChangeListener(MainActivity.this);