3

I am searching for a concrete example in which a Java 8 lambda cannot be used, but a Scala function does. The example should explain the reason why Java 8 lambdas are not considered first class citizens, and so Java 8 cannot be considered a Functional programming language.

EDIT

Java 8 lambdas can be passed as parameters to other method, they can be assigned to variables. So why are not considered first class citizens?

Thanks to all.

riccardo.cardin
  • 7,971
  • 5
  • 57
  • 106
  • Probably because it kinda sounds like homework. – marstran Oct 11 '16 at 08:31
  • This is not a question related to homework. I am an IT professional that is trying to understand deeply why lambdas are not considered first-class citizens. – riccardo.cardin Oct 11 '16 at 08:34
  • 2
    Possible duplicate of [Java 8 lambda expression and first-class values](http://stackoverflow.com/questions/15221659/java-8-lambda-expression-and-first-class-values) – juanpa.arrivillaga Oct 11 '16 at 09:03
  • I fail to see how a question asking for a concrete example can be flagged "too broad", but I agree it's a duplicate. – C4stor Oct 11 '16 at 09:05
  • @juanpa.arrivillaga I don't think my question is a duplication of the question you've indicated. There is no practical example in the answers given to that question. – riccardo.cardin Oct 11 '16 at 09:05
  • 1
    @riccardo.cardin the answer to that question argues that Java 8 lambdas *are* first-class citizens. – juanpa.arrivillaga Oct 11 '16 at 09:06
  • @C4stor, if it's a duplicate, please can you forward me to an answer that gives an example? – riccardo.cardin Oct 11 '16 at 09:07
  • @juanpa.arrivillaga, first sentence of the accepted answer: "I would say that Java 8 closures ("Lambdas") are neither mere syntactic sugar **nor are they first-class values**." – riccardo.cardin Oct 11 '16 at 09:07
  • 1
    @riccardo.cardin keep reading... – juanpa.arrivillaga Oct 11 '16 at 09:08
  • The answer being "yes, lambdas are first class function", no, I can't obviously. Your question is fundamentally biased in that "Java 8 lambdas are not considered first class citizens" is simply false and pure opinion of your part (and maybe your colleagues ?). – C4stor Oct 11 '16 at 09:09
  • @C4stor, common opinion on the Internet is that Java 8 is not a functional programming language. And I agree with this opinion. Also the author of the accepted answer says at the end: "Java 8 doesn't have function types; it has functional interfaces. These are used effectively like function types, but they aren't function types at all. If you have a reference whose type is a functional interface, you have no idea whether it's a lambda, an instance of an anonymous inner class, or an instance of a concrete class that happens to implement that interface. – riccardo.cardin Oct 11 '16 at 09:12
  • 2
    Well, I can't argue about what's common opinion on the Internet. The two tops answers on the question linked say that lambdas are first class citizens in java 8. Whether that reflects the majority opinion on Internet, or whether that makes or not Java 8 a functional programming language, I'll leave it up to you and have no interest in it :) – C4stor Oct 11 '16 at 09:16
  • @C4stor I don't understand how you can decide to vote as duplicate my question if you are not interested to the question and possible answers... – riccardo.cardin Oct 11 '16 at 09:20
  • 1
    @riccardo.cardin The answerable part of the question has already been answered. I vote has duplicate. Simple as that :) – C4stor Oct 11 '16 at 09:25
  • 2
    @riccardo.cardin: it *is* a duplicate, even if you disagree with the answers there. Anyone disagreeing could post a new answer—*there*. That’s the purpose of closing duplicates, centralizing the answers instead of having alternative, possibly contradicting answers about the same thing spread over multiple questions. – Holger Oct 11 '16 at 09:37
  • 1
    @riccardo.cardin You are conflating having functions as first class citizens with a language being a 'purely functional language'. While it is a necessary aspect of a functional language, it isn't sufficient. In other words, Java 8 has first-class functions and it is also not a purely functional language. Scala itself isn't purely functional either, if you accept the criteria that purely functional languages should forbid changing-state and mutable data. – juanpa.arrivillaga Oct 11 '16 at 09:37
  • Ok, probably I found my answer here: [What I miss in Java 8 lambda functions](http://blogs.atlassian.com/2014/03/miss-java-8-lambda-functions/). Java lambdas can be passed as arguments to methods, but such a lambda cannot be invoked as it was a function. – riccardo.cardin Oct 11 '16 at 09:42

0 Answers0