2013年9月17日星期二

When defining static class

My current understanding is that some of the tools
recently did months of Excel operations, multiple functions can realistically
class static Excel{
public static toCsv(arg..){}
public static read(arg..){}
public static write(arg..){}
...
}


then looked at the POI source code examples XLS2CSVmra, suddenly puzzled
why this class is not static
then thought
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
sdf.format(new Date());

if I am to write, would write the class
SimpleDateFormat.format(new Date(),"yyyy-MM-dd")

But the large cattle did not say so.
suddenly feel connected "when defining static class " This can not understand simple questions
good lost , help
------ Solution - -------------------------------------------
in another class internally defined class that does not want to rely on the instantiation of the outer class instantiation , this time can be defined as a static class ( ie , internal static class ) .
------ Solution ---------------------------------------- ----
http://blog.sina.com.cn/s/ blog_605f5b4f0100zbps.html to give a reference here to the more detailed
------ Solution --------------------- -----------------------
directly define static constants .
------ Solution ---------------------------------------- ----

this trouble speaking , visual LZ is to ask static method , but wander static inner classes to go. .
------ Solution ---------------------------------------- ----
SimpleDateFormat should not be tools, only internal static class category , the landlord said should be a static method. .
------ Solution ---------------------------------------- ----

//可以利用SimpleDateFormat来写自己的工具类,比如
public class DateUtil {

public static String getStringDate(){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(new Date());
}
}

use of static methods as well as " single mode" code written much, much more to see , a lot of things naturally understand
------ Solution ----------- ---------------------------------
SimpleDateFormat first new a new object in the call methods .
accordance with the landlord was thinking : SimpleDateFormat.format (new Date (), "yyyy-MM-dd") so format () method is a static method
------ For reference only ---------------------------------------
class static Excel . . .
LZ good creativity
------ For reference only ------------------------------ ---------
wrong , do not care about these details, to understand better
------ For reference only -------------- -------------------------
novice passing . . . . . .

------ For reference only ---------------------------------- -----
static class is doing, there is demand for it ?

没有评论:

发表评论