q*q
2 楼
careercup上有这样一道题:implement a singleton design pattern as a template
such that for any given class Foo, you can call Singleton::instance() and
get a pointer to an instance of a singleton of type Foo
答案是用c++给出的。我用java写出下面的代码,但显然不对,请问上面的问题应该怎
么用java实现呢?
另外对下面不对的代码我也有一些疑问:
public class SingleTon {
private static T t; //报语法错误“annot make a static reference to the
non-static type T”,请问这是什么缘故?
public synchronized static T instance() {
if( t == null ) {
t = new T();//即使t非static,此处也无法instantiate,我想是因为很多
class没有default constructor的原因,这样理解是否对?
}
return t;
}
}
谢谢!
such that for any given class Foo, you can call Singleton::instance() and
get a pointer to an instance of a singleton of type Foo
答案是用c++给出的。我用java写出下面的代码,但显然不对,请问上面的问题应该怎
么用java实现呢?
另外对下面不对的代码我也有一些疑问:
public class SingleTon
private static T t; //报语法错误“annot make a static reference to the
non-static type T”,请问这是什么缘故?
public synchronized static T instance() {
if( t == null ) {
t = new T();//即使t非static,此处也无法instantiate,我想是因为很多
class没有default constructor的原因,这样理解是否对?
}
return t;
}
}
谢谢!
d*e
3 楼
Citizenship Requirement: U.S. or Valid Green Card Holder
Job Duties:
Planning:
• Develop a market-centric strategy for the product or product line,
that includes an analysis of market demand (supported by the Strategic
Marketing Manager and others as needed), customer behavior, competitors,
StandardAero's capabilities and a strategic and market orientation for the
product or product line. Such a plan shall present the evolution of the
product and product portfolio over an appropriate calen
Job Duties:
Planning:
• Develop a market-centric strategy for the product or product line,
that includes an analysis of market demand (supported by the Strategic
Marketing Manager and others as needed), customer behavior, competitors,
StandardAero's capabilities and a strategic and market orientation for the
product or product line. Such a plan shall present the evolution of the
product and product portfolio over an appropriate calen
e*e
4 楼
【 以下文字转载自 Chemistry 讨论区 】
发信人: evence (硬猫), 信区: Chemistry
标 题: 为什么FPD detector比SCD响应灵敏?
发信站: BBS 未名空间站 (Mon Apr 23 20:46:21 2012, 美东)
都是photometric 啊
求分析大佬解释
发信人: evence (硬猫), 信区: Chemistry
标 题: 为什么FPD detector比SCD响应灵敏?
发信站: BBS 未名空间站 (Mon Apr 23 20:46:21 2012, 美东)
都是photometric 啊
求分析大佬解释
g*g
6 楼
Since Java uses type erasure, generics is a compile time trick.
If it can't decide the type in compile time, it can't do instantiation.
template
the
【在 q**q 的大作中提到】
: careercup上有这样一道题:implement a singleton design pattern as a template
: such that for any given class Foo, you can call Singleton::instance() and
: get a pointer to an instance of a singleton of type Foo
: 答案是用c++给出的。我用java写出下面的代码,但显然不对,请问上面的问题应该怎
: 么用java实现呢?
: 另外对下面不对的代码我也有一些疑问:
: public class SingleTon {
: private static T t; //报语法错误“annot make a static reference to the
: non-static type T”,请问这是什么缘故?
: public synchronized static T instance() {
If it can't decide the type in compile time, it can't do instantiation.
template
the
【在 q**q 的大作中提到】
: careercup上有这样一道题:implement a singleton design pattern as a template
: such that for any given class Foo, you can call Singleton::instance() and
: get a pointer to an instance of a singleton of type Foo
: 答案是用c++给出的。我用java写出下面的代码,但显然不对,请问上面的问题应该怎
: 么用java实现呢?
: 另外对下面不对的代码我也有一些疑问:
: public class SingleTon
: private static T t; //报语法错误“annot make a static reference to the
: non-static type T”,请问这是什么缘故?
: public synchronized static T instance() {
s*y
7 楼
大家还要打牌,第一个是要招安小毛驴:)不然没法玩了。
m*r
10 楼
since you need to return any class, what you need is a map from Class to
Object.
private static Map, or Map, i am not sure.
and use reflection to instantiate the object.
template
the
【在 q**q 的大作中提到】
: careercup上有这样一道题:implement a singleton design pattern as a template
: such that for any given class Foo, you can call Singleton::instance() and
: get a pointer to an instance of a singleton of type Foo
: 答案是用c++给出的。我用java写出下面的代码,但显然不对,请问上面的问题应该怎
: 么用java实现呢?
: 另外对下面不对的代码我也有一些疑问:
: public class SingleTon {
: private static T t; //报语法错误“annot make a static reference to the
: non-static type T”,请问这是什么缘故?
: public synchronized static T instance() {
Object.
private static Map
and use reflection to instantiate the object.
template
the
【在 q**q 的大作中提到】
: careercup上有这样一道题:implement a singleton design pattern as a template
: such that for any given class Foo, you can call Singleton::instance() and
: get a pointer to an instance of a singleton of type Foo
: 答案是用c++给出的。我用java写出下面的代码,但显然不对,请问上面的问题应该怎
: 么用java实现呢?
: 另外对下面不对的代码我也有一些疑问:
: public class SingleTon
: private static T t; //报语法错误“annot make a static reference to the
: non-static type T”,请问这是什么缘故?
: public synchronized static T instance() {
r*l
12 楼
public class Singleton {
private static final Map, Object> map = new HashMap,
Object>();
public synchronized static T instance(Class c)
throws InstantiationException, IllegalAccessException {
if (!map.containsKey(c)) {
T o = c.newInstance();
map.put(c, o);
}
return (T) map.get(c);
}
}
template
the
【在 q**q 的大作中提到】
: careercup上有这样一道题:implement a singleton design pattern as a template
: such that for any given class Foo, you can call Singleton::instance() and
: get a pointer to an instance of a singleton of type Foo
: 答案是用c++给出的。我用java写出下面的代码,但显然不对,请问上面的问题应该怎
: 么用java实现呢?
: 另外对下面不对的代码我也有一些疑问:
: public class SingleTon {
: private static T t; //报语法错误“annot make a static reference to the
: non-static type T”,请问这是什么缘故?
: public synchronized static T instance() {
private static final Map
Object>();
public synchronized static
throws InstantiationException, IllegalAccessException {
if (!map.containsKey(c)) {
T o = c.newInstance();
map.put(c, o);
}
return (T) map.get(c);
}
}
template
the
【在 q**q 的大作中提到】
: careercup上有这样一道题:implement a singleton design pattern as a template
: such that for any given class Foo, you can call Singleton::instance() and
: get a pointer to an instance of a singleton of type Foo
: 答案是用c++给出的。我用java写出下面的代码,但显然不对,请问上面的问题应该怎
: 么用java实现呢?
: 另外对下面不对的代码我也有一些疑问:
: public class SingleTon
: private static T t; //报语法错误“annot make a static reference to the
: non-static type T”,请问这是什么缘故?
: public synchronized static T instance() {
q*q
14 楼
Thank you! I got it.
【在 r*****l 的大作中提到】
: public class Singleton {
: private static final Map, Object> map = new HashMap,
: Object>();
: public synchronized static T instance(Class c)
: throws InstantiationException, IllegalAccessException {
: if (!map.containsKey(c)) {
: T o = c.newInstance();
: map.put(c, o);
: }
: return (T) map.get(c);
【在 r*****l 的大作中提到】
: public class Singleton {
: private static final Map
: Object>();
: public synchronized static
: throws InstantiationException, IllegalAccessException {
: if (!map.containsKey(c)) {
: T o = c.newInstance();
: map.put(c, o);
: }
: return (T) map.get(c);
S*h
21 楼
赞~
【在 r*****l 的大作中提到】
: public class Singleton {
: private static final Map, Object> map = new HashMap,
: Object>();
: public synchronized static T instance(Class c)
: throws InstantiationException, IllegalAccessException {
: if (!map.containsKey(c)) {
: T o = c.newInstance();
: map.put(c, o);
: }
: return (T) map.get(c);
【在 r*****l 的大作中提到】
: public class Singleton {
: private static final Map
: Object>();
: public synchronized static
: throws InstantiationException, IllegalAccessException {
: if (!map.containsKey(c)) {
: T o = c.newInstance();
: map.put(c, o);
: }
: return (T) map.get(c);
相关阅读
AICHE有career fair吗?兼求工作referPhD 找工作求推荐Amex SPG卡送30K points 免费送600刀现金 限时促销paper help (转载)再问PE考试requirements谁有calcium carbonate precipitation potential (CCPP)的计(转载)真心求助!如何保护自己多年的心血?全球著名品酒俱乐部,只需$69即可购买12瓶高档葡萄酒送高档开瓶器转:全方位利用dropbox (不只是存储!)信用分数知多少?Poor or Excellent?免费查询,尽快提高到700分什么叫Pinch Analysis?One PhD position available in ChemE at the University of AkronASTM standardPosition opening, photoresist chemsitryPrinceton的Haw Yang如何?干了很多苦活累活前任老板发文章不写我的名字怎么半faculty positionAmex Blue Cash preferred 6%现金回扣+$150bonus超市专用信用卡anyone looking for a faculty position in Chem Eng?请教:碳黑dispersion