从另一个类传递的方法 [英] Passing a method from another class
问题描述
我想从一个类调用一个方法到另一个,不知道这是可能的,而不扩展包含方法的类。我试图导入包,这样,我认为方法应该允许使用,因为它是一个公共方法,但是这不是sucesfull ..
试图使用此<一href=\"http://thedevelopersinfo.word$p$pss.com/2009/10/15/passing-data-between-activities-in-android/\"相对=nofollow>链接作为参考,但我不明白它(因为Android游戏应用程序。)
一个伪code,以体现
类1
2级2级:进口package.class 1;
类1.this.method(); - &GT;错误:在类型1类没有外围实例在范围acessible
其他方法可能是,为其他类对象,然后调用该对象的方法。类似下面。
新ClassA的()yourMethod()。
I want to call a method from one class to another, don't know if that's possible without extends the class that contains the method. I've tried to import the package, that way I thought the method should be allow to use since it's a public method but that was not sucesfull..
tried to use this link as reference, but I didn't understand it (since is an app for android..)
A pseudo-code to exemplify
class 1
class 2
class 2:
import package.class 1;
class 1.this.method(); -> Error: No enclosing instance of the type class 1 in is acessible in scope
Other way may be, create object for other class and then invoke the method on that object. Something like below.
new ClassA().yourMethod();
这篇关于从另一个类传递的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!