z****e 发帖数: 54598 | 1
牛肉姐,你这个不熟悉吧,ide可以自动reformat所有code的
我不觉得是空格的问题,多半是类似这种
public void Func(int...){...
private _var
public class myClass{... |
|
z****e 发帖数: 54598 | 2
牛肉姐,你这个不熟悉吧,ide可以自动reformat所有code的
我不觉得是空格的问题,多半是类似这种
public void Func(int...){...
private _var
public class myClass{... |
|
s*****n 发帖数: 994 | 3 Myclass a = function()
用gdb看function的返回根本没有改变a,=也没有重载过,有人碰到过这种情况吗? |
|
p*********t 发帖数: 2690 | 4 Myclass是一个class名字吗?function()的返回值的data type是什么? |
|
d****p 发帖数: 685 | 5 This is equivalent to Myclass a(function());
You are initializing instance a with the return of function(), not creating
it then assigning the return of function() to a later on. |
|
w*s 发帖数: 7227 | 6 say i have a txt file
line 1
line 2
# this is comment, no read
# comment 2
line 3
...
i start with
string all_stocks = System.IO.File.ReadAllText(FileName);
char[] delimiters = new char[] { ' ', 'r', 'n' };
string[] each_line = myClass.Split(delimiters,
StringSplitOptions.RemoveEmptyEntries);
how to skip comment lines pls ? |
|
x**n 发帖数: 29 | 7 应该是没有锁住.应为你这只是一个同步方法.
只可以保证由myClass产生的实例的该方法是锁住的.
想锁住某个对象,可以用这个对象来做同步钥匙.
//个人意见,不知道对不对. |
|
f********h 发帖数: 149 | 8 I tried to use them altogether, but there is a problem.
If I invoke junit from ant, it complains the log4j system
is not properly set up. But if I run my code directly from console
using java myclass there is no problem.
Any solution to this? |
|
n*****k 发帖数: 123 | 9
The difference is not the class and struct, but the way how you can create the
data type.
Unlike C++, C#, java doesn't not support stack object, which means the only
way you can create an object is from the heap by using new operator, which is
kind of slow compared to stack memory. For example you can say
MyClass mc;
mc looks like a Stack object in C++, but if you try to use the method of mc
without initializing the mc properly, guess what, you will get a
java.lang.NullPointerException, Which m |
|
c*****s 发帖数: 214 | 10 非也。
可以做个小试验。在Class.forName里设个断点
ClassA myClass = null;
System.out.println(ClassA.class);
你会发现ClassA在第二行被加载。
另一个方法是在ClassA里加个static块,看看什么时候执行。 |
|
s*********g 发帖数: 2350 | 11 很菜的关于package 的问题, 请大家不要耻笑啊。。。
编译文件 A.java 需要用到 文件B.java中的class "MyClass"
文件B的目录是 D:\Programming\JavaBook\ThinkingInJava\TIJ4-code\access\
mypackage
文件B.java的第一行是
package access.mypackage;
文件A.java的第一行是
import access.mypackage.*;
我是这麽设置CLASSPATH的
右键点击project 的property, 选 Java Build Path-->Libraries-->Add Variable |
|
s*******e 发帖数: 3042 | 12 you meant something like this?
class MyClass {
private SingletonClass sClass = null;
public SingletonClass getInstance() {
if (sClass == null)
synchronized(this) {
if (sClass == null)
sClass = new SingletonClass();
}
return sClass;
}
....
}
This is the only implementation that I can think of to avoid going
through synchronized block every time, but I don't think it works in 1.4
and before |
|
d****i 发帖数: 4809 | 13 一般的普通的class,可以通过MyClass.class得到,但是如果有Generics的情况,由于
type erasure,就没法得到它的class,比如我想用List.class,就会报错,
但是有些class method只接受这样的input argument:
public void foo(Class> class)
如果我想传入一个List的类的话,怎么办?没法用
foo(List.class) |
|
c******n 发帖数: 4965 | 14 I have the following code, which includes a closure:
class MyClass:
outer_var = 1
def run():
class Inner():
def run_inner():
print self.outer_var
at the last line, I want to refer to the member of the outer class,
but now the "self" actually refers to Inner class.
this is because python does not have a proper scope. so apart from
assigning outer_var to a tmp var, is there any way to refer to
outer_var?
thanks |
|
d******e 发帖数: 194 | 15 I don't understand....
MyClass::Inner is supposed to be the return type. what does 'typename'
mean?
Thanks for response anyway. |
|
t****t 发帖数: 6806 | 16 since this is a template, myclass::inner is not necessary a type -- or at
least compiler doesn't know that (to be precise, it's a dependent name). so
you have to tell the compiler, it's a type. |
|
m*******o 发帖数: 264 | 17 5. Suppose you're responsible for writing class MyClass as part of a static
library.
a. How do you enforce that a single instance of this class be used at
compile-time.
b. How do you enforce that instances only be allocated on the stack, but
not on the heap, at compile-time. |
|
b***m 发帖数: 58 | 18 Here is another one, don't quiet understand what it is asked.
Suppose you're responsible for writing class MyClass as part of a static
library.
a) How do you enforce that a single instance of this class be used at
compile-time?
b) How do you enforce that instances only be allocated on the stack, but not
on the heap, at compile-time? |
|
t****t 发帖数: 6806 | 19 不管是partial specialization还是full specialization,类都要重写过.
你倒是可以试着把datatype做成模板,比如说:
template struct datatype_trait
{
typedef T1 data_type;
};
template <> struct datatype_trait
{
typedef S data_type;
};
template class myclass
{
typedef typename datatype_trait::data_type datatype;
...
};
|
|
|
d*****u 发帖数: 17243 | 21 myObj->myFunction()实际上是*(myObj).myFunction()的缩写
如果你定义了myClass类型的变量,不能用->访问成员
只能用 myObj.myFunction() |
|
e****d 发帖数: 895 | 22 I think the first one should be
template <> class MyClass {}
which is an explicit specialization.
The other two are partial specialization and primary template. |
|
c**********e 发帖数: 2007 | 23 第一个人的回答:
1. Struct has public access by default (class has private access).
2. When you are going to inherit from that class.
第一个人的第一点我明白。但第二点也是谈public/private的问题吗?
第二个人的回答:
Another difference between struct and class can be shown if you try to
declare struct MyClass; or class MyStruct; Both keywords are not
interchangeable in declarations, not just for class/struct definitions.
第二个人的回答是什么意思?
Source:
http://stackoverflow.com/questions/50447/favorite-c-interview-q |
|
G***l 发帖数: 355 | 24 Java和C#的设计思想是很类似,做的也是类似的事情。可以说C#是微软版的Java。这两
个语言也别谈谁抄袭谁,互相抄。比方说enum就是C#先有然后Java后来才有的。但是
Java的enum比C#好用。其实都是抄的前人的。但现在而言C#就是比Java更好的语言。别
说这些就是语法糖什么的,多了少了无所谓,就是这些决定了一个语言的易用性。
我以前是写Java的,这两年用C#,真的比Java顺手很多。像C#的delegate的设计真的非
常好。那些functional的东西也非常好用,大大简化代码,不止是行数变少,而且真的
可维护性好了很多。以前好几行,要写什么循环判断啊之类的一行就搞定,而且意思很
明确,看别人的代码容易了很多。linq也非常好,虽然没有这些可以写出一样功能的代
码,但就是不一样。
也别担心人滥用。C#毕竟还是个OO概念为主的静态语言,比Java还OO。int什么的也是
对象,分valuetype跟reference type而已,跟函数式也结合的很好,function也都是
对象。我们这儿我没见过有人写C#滥用那些的。这跟C++不同,那么多乱七八糟的东西
还都得用着... 阅读全帖 |
|
p***r 发帖数: 1098 | 25 Int 和 float的数要convert成NSNumber, and then add to NSMutableArray
@synthesize用来告诉编译器generated getter/setter code
(最新的xcode里,@synthesize这一行可以不写了)
你直接这样写:
@interface MyClass: NSObject
@property (nonatomic, strong) NSMutableArray* operandStack;
@end
自动生成_operandStack的instance variable和self.operandStack的setter和getter |
|
p***r 发帖数: 1098 | 26 Int 和 float的数要convert成NSNumber, and then add to NSMutableArray
@synthesize用来告诉编译器generated getter/setter code
(最新的xcode里,@synthesize这一行可以不写了)
你直接这样写:
@interface MyClass: NSObject
@property (nonatomic, strong) NSMutableArray* operandStack;
@end
自动生成_operandStack的instance variable和self.operandStack的setter和getter |
|
N****M 发帖数: 158 | 27 这个construction function 后面加冒号是什么意思啊,正在学习中,不知道叫什么名
字,查也查不到。
MyClass(void (*cb)()) : done(cb) {}
poitned |
|
s****y 发帖数: 503 | 28 比如我有一个类
class MyClass {
private String name;
private Integer age;
private final int MAXIMUM = 25;
private final int MINIMUM = 19;
}
是不是不应该考虑常量,只考虑变量?用name和age让Eclipse自动生成的hashcode和
equals是不是最好的? |
|
z*******3 发帖数: 13709 | 29 简单, 写起来快,是真的java script
尤其是如果你对class MyClass{
public static void main(String[] args){}
}
这些感到厌烦的话
rxjava就是fp那些东西啊,map,filter,flatmap etc.
用来排除金字塔很管用啊
每次返回一个observable,然后subscribe你的callback method就好了
subscribe完之后继续返回observable,如此循环,就不用金字塔了
这些在同步中很容易写,在fp和异步中就变得麻烦起来
但是最终可以写成
a.map()
.flatmap()
.filter()
...这种方式
比之前的
a.map(...,flatmap(...,filter()))
这种美观多了
如果不是fp的话,这里还需要嵌套一层object做匿名类,烦死
而且这个做下去就是streaming,一旦streaming开始推广
以后这种搞法会越来越多
/* */, 还不如直接用 [email protected]
/* */ 了 |
|
z****e 发帖数: 54598 | 30 对于同一台jvm上的spring用法几乎是一样的
无论是不是toy还是prod. code
如果分布式的话,spring就不管了,你自己要想办法处理跨机器的通信
比如用jms,或者web service,或者rmi
总有一种rpc适合你
如果你非要举出例子来
public class MyClass{
@Autowire
private UrClass urClass
public void doSth(...){
...
urClass.func(...);
...
}
}
基本上就这个模式 |
|
T*******e 发帖数: 4928 | 31 抛快砖头哦。 我感觉auto还是慎用。
auto my_object =new MyClass(); //good to read
auto abc(int n) { //bad
// god knows what happens here
// ...
return whaterever;
}
auto lmn (double x){ //bad
//god knows what happens here
//...
auto whatever2 = abc(n);
//....
return whatever2;
}
// .......
auto xyz(const string& s){ //bad
//god knows what happens here
//...
auto do_you_know_me = lmn(x);
//....
return do_you_k... 阅读全帖 |
|
d****i 发帖数: 4809 | 32 没看懂,头文件里应该没有任何具体实现的细节,只有函数/类/变量的声明,怎么会有
问题呢?比如下面的头文件:
//my_header.h
int foo1();
void foo2(char* a);
class MyClass {
public:
bool foo3(int a);
};
所有的实现都应该放在cpp文件里面进行,哪怕是用了template也是如此。 |
|
b***k 发帖数: 2673 | 33 ☆─────────────────────────────────────☆
bbram (bob) 于 (Sat May 3 13:39:31 2008) 提到:
Suppose you're responsible for writing class MyClass as part of a static
library.
a) How do you enforce that a single instance of this class be used at
compile-time?
b) How do you enforce that instances only be allocated on the stack, but not
on the heap, at compile-time?
此题是问singleton 的implementation 吗?
☆─────────────────────────────────────☆
binrose (BigHead) 于 (Sat May 3 17:11:15 2008) 提到:
Yes it i |
|