Unchecked Cast Warning when calling 'Class.forName'

前端 未结 4 593
天命终不由人
天命终不由人 2021-01-02 16:52

My code is as follows

package com.foo;

public class TestComposition {
    public static void main(String[] args) {
        try {
            Class

        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-02 17:43

    If you knew the exact class, you wouldn't need to use Class.forName

    Class fooClass = Foo.class;
    

    It only makes sense to do this when you don't know the type.

提交回复
热议问题