0

New to mobile development and thought I'd follow along with this tutorial. This is hopefully a simple question. If someone could just tell me what the --> is called (is it a pointer?) or what causes the (e) --> code to be light gray in color after typed, I could do some more research on my own problem here.

youtube.com/watch?v=RagA8g9A5Qc

In the video link below at 10:58 (pause video) you will see some code showing

uploadTask.addOnFailureListener ((e) --> { {finish(); }};

at 10:42 in the video you see similar symbol

    `mProfileImage.setOnClickListener((view) --> {saveUserInformation(); }};`

Could someone please advise what the --> is called and how I might get the (e) --> to appear in the auto-populate functions dialog box as you start typing? Am I missing a file or class?

I think it might be an IDE settings since just above those lines of code in his video you see the following line:

- bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);

but in my IDE I see the word "quality"

- bitmap.compress(Bitmap.CompressFormat.JPEG, quality 20, baos); 

appear when the value 20 was typed. It's a light grey color similar to the (e) and --> in his code which for some reason won't work in my editor or code.

TomYumGuy
  • 55
  • 1
  • 10
Joe
  • 35
  • 8

2 Answers2

1

Assuming you're using Java 8+, the -> operator is used for lambda functions.

A lambda is an anonymous function, useful for functions that you'll only be using once, or passing as an argument. Read more here.

pawlactb
  • 109
  • 1
  • 9
0

Basically, (e) -> {...} is a lambda, you can read more about this here https://kotlinlang.org/docs/reference/lambdas.html, but it's, in basic terms, a block of code that can be executed. The e is the parameter coming from the caller and the -> is just syntax to denote the lambda followed by the code, the "quality" in grey letters that you mention is just the name of a parameter in the compress method, which the IDE shows so you can properly fill method calls without looking up the docs or the source.

EDIT: Also, bear in mind it should be -> not -->, in both Java and Kotlin, that could be the source of your "grey letters" issue.

Eduardo Naveda
  • 1,880
  • 3
  • 15
  • 30
  • To start, sorry for the poor post syntax formatting. Been a while since I posted code questions. I went back through the tutorial videos and Video 9 @ 28:25 shows the code. What I didn't notice is that it is just collapsed code LOL. [link](https://www.youtube.com/watch?v=MUiZhCUHXhk&list=PLxabZQCAe5fio9dm1Vd0peIY6HLfo5MCf&index=9) He changes his public void 'onFailure()' to become the the lambda code seen shortly after.by collapsing the function on the side margin This answered my problem. Appreciate the term for lambda. – Joe May 18 '18 at 02:35