You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by GitBox <gi...@apache.org> on 2019/05/22 19:15:39 UTC

[GitHub] [samza] dnishimura commented on a change in pull request #1044: SAMZA-2204: Consolidate some reflection-related utility methods into a common class

dnishimura commented on a change in pull request #1044: SAMZA-2204: Consolidate some reflection-related utility methods into a common class
URL: https://github.com/apache/samza/pull/1044#discussion_r286621067
 
 

 ##########
 File path: samza-core/src/main/java/org/apache/samza/util/ReflectionUtil.java
 ##########
 @@ -0,0 +1,96 @@
+/*
+ * 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.samza.util;
+
+import java.lang.reflect.Constructor;
+import java.util.stream.IntStream;
+import org.apache.commons.lang3.Validate;
+import org.apache.samza.SamzaException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ReflectionUtil {
+  private static final Logger LOG = LoggerFactory.getLogger(ReflectionUtil.class);
+
+  private ReflectionUtil() {
+  }
+
+  /**
+   * Instantiate an object of type T from a given className using the given classLoader.
+   *
+   * @param className full class name (including namespace)
+   * @param clazz type of object to return
+   * @param classLoader classloader to use to load className
+   * @return object of type T created from the empty constructor of the class corresponding to className
+   * @throws SamzaException if class instance cannot be created
+   */
+  public static <T> T getObj(String className, Class<T> clazz, ClassLoader classLoader) {
 
 Review comment:
   Maybe add some `Precondition` checks in each of the methods?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services