【发布时间】:2014-08-24 16:01:27
【问题描述】:
我正在尝试以一种简单的方式处理类,但我无法实现它......
到目前为止...我用它的构造函数和方法创建了一个separateClass.java,但是在Main.java中,我以这种方式调用了separateClass.java的方法...
// Current way...
separateClass sp = new separateClass(myPathString);
String newPath = sp.myMethod();
// The way I would like...
String newPath = myMethod(myPathString);
// ADDED AFTER RESPONSE...
// This way helps me when I have more classes (.javas)
String newThig = separateClass.myMethod(myPathString);
String anotherThing = myOtherLibrary.methodForSomeThing(someString);
String numCheck = myCalculations.terrain(altitude, latitude);
// Note: The static way is just recomended with simples processes that don't
// need many objects or constructors.
// so far this is what I understand.
有可能吗?我该怎么做? 我很欣赏一些想法! :)
已编辑...
public class separateClass{
/* Not needed if static (for novices)
String myPathString;
public Imagen_DirectorioGestor(String myPathString) {
this.myPathString= myPathString;
}
*/
public static String myMethod(String myPathString){
File file = new File(myPathString);
newPath = ...;
return newPath;
}
}
【问题讨论】:
标签: java android class methods