Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

immutability - Typesafe effectively read only java collections?

I'm searching for a java library for collections with no methods that allow for mutations. effectively immutable read only collections.

By that I mean, NO METHODS. Not like the usual Java immutable collections that have methods like add or remove that throw an exception when called. No... I want the compiler to let me know I'm trying to do something not allowed, instead of some error at runtime.

I know it exists because I've used it, but I cannot remember the name of such library.

question from:https://stackoverflow.com/questions/66051737/typesafe-effectively-read-only-java-collections

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Eclipse Collections: https://www.eclipse.org/collections/

Their own guide on immutable collections says:

All of the basic containers in Eclipse Collections have interfaces for both mutable and immutable (unchangeable) forms. This departs somewhat from the JCF model, in which most containers are mutable.

An immutable collection is just that - once created, it can never be modified, retaining the same internal references and data throughout its lifespan. An immutable collection is equal to a corresponding mutable collection with the same contents; a MutableList and an ImmutableList can be equal.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...