Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Java 8 "view"?

Tags:

I'm watching a talk by Paul Philips :

http://www.youtube.com/watch?v=TS1lpKBMkgg

at 12:48 he says "in Java 8 their views actually work" when comparing Scala and Java

What are Java "views" and what is Scala's equivalent ?

update : Thanks to Daniel's answer I found this article helpful : http://www.scala-lang.org/docu/files/collections-api/collections_42.html

like image 293
blue-sky Avatar asked Oct 31 '13 23:10

blue-sky


People also ask

What is a Java 8?

Java 8 is a revolutionary release of the world's #1 development platform. It includes a huge upgrade to the Java programming model and a coordinated evolution of the JVM, Java language, and libraries.

What is Java 8 mostly used for?

JAVA 8 is a major feature release of JAVA programming language development. Its initial version was released on 18 March 2014. With the Java 8 release, Java provided supports for functional programming, new JavaScript engine, new APIs for date time manipulation, new streaming API, etc.

What is a Java 8 stream?

Introduced in Java 8, the Stream API is used to process collections of objects. A stream is a sequence of objects that supports various methods which can be pipelined to produce the desired result.


1 Answers

Java 8's Stream is what he means by views. They have two important properties:

  1. They are non-strict, which means they only produce the result on-demand.
  2. They "fuse" together multiple operations, so you can do multiple map or filter calls, and the original collection will still be iterated only once.

Scala's equivalent are the various View collections, which you can get by calling .view on an existing collection. They do have these properties -- they are the defining properties, after all -- but are plagued with deficiencies and bugs, not to mention a very complex implementation.

Paul has toyed with alternative implementations for it on and off, but it has never been a priority replacing them.

like image 97
Daniel C. Sobral Avatar answered Sep 29 '22 03:09

Daniel C. Sobral