Who is using Manifold?
Sampling of companies using Manifold:
What can you do with Manifold?
Extension Methods
Add your own methods to existing Java classes, even String, List, and File. Eliminate boilerplate code. ▶ Check it out!
String greeting = "hello";
greeting.myMethod(); // Add your own methods to String!
Delegation
Favor composition over inheritance. Use @link
and @part
for automatic interface implementation forwarding and true delegation.
> class MyClass implements MyInterface { > @link MyInterface myInterface; // transfers calls on MyInterface to myInterface > > public MyClass(MyInterface myInterface) { > this.myInterface = myInterface; // dynamically configure behavior > } > > // No need to implement MyInterface here, but you can override myInterface as needed > } > ``` ### [Properties](https://github.com/manifold-systems/manifold/tree/master/manifold-deps-parent/manifold-props) Eliminate boilerplate getter/setter code, improve your overall dev experience with properties. ```java public interface Book { @var String title; // no more boilerplate code! } // refer to it directly by name book.title = "Daisy"; // calls setter String name = book.title; // calls getter book.title += " chain"; // calls getter & setter
Additionally, the feature automatically infers properties, both from your existing source files and from compiled classes your project uses. Reduce property use from this:
Actor person = result.getMovie().getLeadingRole().getActor(); Likes likes = person.getLikes(); likes.setCount(likes.getCount() + 1);
to this:
result.movie.leadingRole.actor.likes.count++;
Tuple expressions
Tuple expressions provide concise syntax to group named data items in a lightweight structure.
var t = (name: "Bob", age: "35");
System.out.println("Name: " + t.name + " Age: " + t.age);
var t = (person.name, person.age);
System.out.println("Name: " + t.name + " Age: " + t.age);
You can also use tuples with new auto
type inference to enable multiple return values from a method.
Unit Expressions
Unit or binding operations are unique to the Manifold framework. They provide a powerfully concise syntax and can be applied to a wide range of applications.
import static manifold.science.util.UnitConstants.*; // kg, m, s, ft, etc
...
Length distance = 100 mph * 3 hr;
Force f = 5.2 kg m/s/s; // same as 5.2 N
Mass infant = 9 lb + 8.71 oz;
Ranges
Easily work with the Range API using unit expressions. Simply import the RangeFun constants to create ranges.
// imports the `to`, `step`, and other "binding" constants
import static manifold.collections.api.range.RangeFun.*;
...
for (int i: 1 to 5) {
out.println(i);
}
for (Mass m: 0kg to 10kg step 22r unit g) {
out.println(m);
}
Science
Use the manifold-science framework to type-safely incorporate units and precise measurements into your applications.
import static manifold.science.util.UnitConstants.*; // kg, m, s, ft, etc.
...
Velocity rate = 65mph;
Time time = 1min + 3.7sec;
Length distance = rate * time;
#if JAVA_8_OR_LATER @Override public void setTime(LocalDateTime time) {…} #else @Override public void setTime(Calendar time) {…} #endif
### [Structural Typing](https://github.com/manifold-systems/manifold/tree/master/manifold-deps-parent/manifold-ext#structural-interfaces-via-structural)
Unify disparate APIs. Bridge software components you do not control. Access maps through type-safe interfaces. [ **▶** Check it out!](http://manifold.systems/images/structural%20typing.mp4)
```java
Map<String, Object> map = new HashMap<>();
MyThingInterface thing = (MyThingInterface) map; // O_o
thing.setFoo(new Foo());
Foo foo = thing.getFoo();
out.println(thing.getClass()); // prints "java.util.HashMap"
Type-safe Reflection
Access private features with @Jailbreak to avoid the drudgery and vulnerability of Java reflection. ▶ Check it out!
@Jailbreak Foo foo = new Foo();
// Direct, *type-safe* access to *all* foo's members
foo.privateMethod(x, y, z);
foo.privateField = value;
Checked Exception Handling
You now have an option to make checked exceptions behave like unchecked exceptions! No more unintended exception swallowing. No more try/catch/wrap/rethrow boilerplate!
List<String> strings = ...;
List<URL> urls = strings.stream()
.map(URL::new) // No need to handle the MalformedURLException!
.collect(Collectors.toList());
String Templates
Inline variables and expressions in String literals, no more clunky string concat! ▶ Check it out!
int hour = 15;
// Simple variable access with '$'
String result = "The hour is $hour"; // Yes!!!
// Use expressions with '${}'
result = "It is ${hour > 12 ? hour-12 : hour} o'clock";
Projects
The Manifold project consists of the core Manifold framework and a collection of sub-projects implementing SPIs provided by the core framework. Each project consists of one or more dependencies you can easily add to your project:
Manifold : SQL
Manifold : GraphQL
Manifold : JSON
Manifold : XML
Manifold : YAML
Manifold : CSV
Manifold : Property Files
Manifold : Image
Manifold : Dark Java
Manifold : JavaScript
Manifold : String Interpolation
Manifold : (Un)checked Exceptions
Manifold : Collections
Manifold : I/0
Manifold : Text
Experiment with sample projects:
Chat
Join our Slack Group to start a discussion, ask questions, provide feedback, etc. Someone is usually there to help.