
jsweet.util.union.Union Maven / Gradle / Ivy
The newest version!
/*
* JSweet - http://www.jsweet.org
* Copyright (C) 2015 CINCHEO SAS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jsweet.util.union;
/**
* This interface is an auxiliary type used by JSweet to define
* union types.
*
*
* A union type is a type which can be cast to one of its union-ed types. For
* instance:
*
*
* Union<String, Number> u = ...;
* String s = union(u);
* // or:
* Number n = union(u);
*
*
*
* Note that Java will not complain when casting to a type that is not part of
* the union, but the JSweet transpiler will.
*
*
* Union<String, Number> u = ...;
* Date d = union(u); // compiles in pure Java, but not in JSweet
*
*
*
* When a method expects a union, such as the following m
method:
*
*
* void m(Union<String, Number> p);
*
*
* Then it can be called with a String or a Number, by first translating to a
* union:
*
*
* String s = ...
* m(union(s));
*
*
*
* In case of union types of more than two types, one can extend the
* Union
interface for accepting more type parameters. For
* instance, to define a union type that takes 3 arguments, just write:
*
*
* public interface Union3 extends Union
*
* @author Renaud Pawlak
*
* @param
* @param
*/
public interface Union {
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy