How to quote classes without package structure

xiaoxiao2021-03-06  92

This problem stems from a post from Java version of users who cannot be used directly by IMPORT, the compiler will be reported: Cannot Resolve Symbol Lenovo to create an object in addition to NEW can be created with a Class. Forname (). NewInstance () How to get the instance of the class is written with a test example as follows: //myshow.java// The class public class myshow {public string show () {for the call for the called structure definition Return "None Package";}} // myclass.java// to test the called class package com.zcjl.test.base;

Import java.lang.reflect.method;

Public class myclass {public static void main (string [] args) {Try {Object obj = class.Forname ("myshow"). newinstance (); class clazz = obj.getClass (); method method = Clazz.getMethod (" SHOW ", NULL); String ReturnValue = (String) method.invoke (obj, null); system.out.println (ReturnValue);} catch (exception e) {E.PrintStackTrace ();}}} bingo! Compile, run myclass.class, the console returns None Package

转载请注明原文地址:https://www.9cbs.com/read-102171.html

New Post(0)