从属于该类的对象访问类方法

时间:2019-02-10 11:13:28

标签: java

我正在尝试制作一个checkFalse方法,其中我将Object作为参数。我现在要检查该Object是否与this.getClass()相同。如果它是同一类型,我现在想将Object强制转换为该类,以便访问该对象类的方法!

例如,如何从该f对象访问SomeMethod?我正在尝试将对象F转换为类testMain。

错误:无法转换为testMain

class testMain implements testest
{

}

interface testest
{
    public default boolean SomeMethod()
    {

    }

    public default boolean checkFalse(Object f) throws  ClassCastException
    {
        try 
        {
            f = this.getClass();
        } 
        catch (ClassCastException exception) 
        {
            throw exception;
        }
        f = (testMain)f; //Here. How do i turn this object to the    class testMain so that i can access that objects methods? For example, how can i access the SomeMethod through this f object?
     }
}

1 个答案:

答案 0 :(得分:0)

=Count(IIf([Attendance],"P"))