chaokunyang commented on code in PR #3062:
URL: https://github.com/apache/fory/pull/3062#discussion_r2638538294


##########
java/fory-core/src/main/java/org/apache/fory/type/union/Union2.java:
##########
@@ -0,0 +1,191 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.fory.type.union;
+
+/**
+ * A typed union that can hold one of two alternative types. The active 
alternative is identified by
+ * an index (0 or 1).
+ *
+ * <p>This class extends {@link Union} and provides a type-safe way to 
represent values that can be
+ * one of two types, similar to Rust's Result or Either types.
+ *
+ * <p>Usage example:
+ *
+ * <pre>{@code
+ * // Create a union holding a String (type T1, index 0)
+ * Union2<String, Long> union1 = Union2.ofT1("hello");
+ *
+ * // Create a union holding a Long (type T2, index 1)
+ * Union2<String, Long> union2 = Union2.ofT2(100L);
+ *
+ * // Get the value
+ * if (union1.isT1()) {
+ *     String value = union1.getT1();
+ * }
+ * }</pre>
+ *
+ * <p>For unions with more than 6 types, use the generic {@link Union} class 
instead.
+ *
+ * @param <T1> the first alternative type
+ * @param <T2> the second alternative type
+ * @see Union
+ * @see Union3
+ * @see Union4
+ * @see Union5
+ * @see Union6
+ */
+public class Union2<T1, T2> extends Union {

Review Comment:
   could we mark `Union2~6` as final class?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to