很多人都熟悉C语言中的hello world程序:
#include <stdio.h>
main ()
{
printf ("hello world");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么有些在main()函数之前,int如下所示:
int main()
Run Code Online (Sandbox Code Playgroud)
另外,我已经看到void输入的内容()如下:
int main(void)
Run Code Online (Sandbox Code Playgroud)
这似乎是额外的打字,但也许这是一个在其他情况下支付红利的最佳做法?
另外,main()如果你要返回一个字符串,为什么会先加一个int?如果有的话,人们会期望:
char main(void)
Run Code Online (Sandbox Code Playgroud)
关于为什么我们在函数结束时返回0也很模糊.
考虑以下实体类,例如,与EclipseLink 2.0.2一起使用 - 其中link属性不是主键,但仍然是唯一的.
@Entity
public class Profile {
@Id
private Long id;
@Column(unique = true)
private String link;
// Some more attributes and getter and setter methods
}
Run Code Online (Sandbox Code Playgroud)
当我插入具有该link属性的重复值的记录时,EclipseLink不会抛出a EntityExistsException,而是抛出a DatabaseException,并显示消息,说明违反了唯一约束.
这似乎不是很有用,因为没有一种简单的,独立于数据库的方法来捕获此异常.处理这个问题的建议方法是什么?
我考虑过的一些事情是:
DatabaseException- 我担心这个错误代码是数据库的本机错误代码;Profile具有特定值的a的存在link- 这显然会导致大量多余的查询.我有一个表到实体(让我们称之为人)和属性(一个人可以有任意数量的属性).例如:
Name Age
--------
Jane 27
Joe 36
Jim 16
Run Code Online (Sandbox Code Playgroud)
Name Property
-----------------
Jane Smart
Jane Funny
Jane Good-looking
Joe Smart
Joe Workaholic
Jim Funny
Jim Young
Run Code Online (Sandbox Code Playgroud)
我想写一个有效的选择,根据年龄选择人,并返回他们的全部或部分属性.
Ex: People older than 26
Name Properties
Jane Smart, Funny, Good-looking
Joe Smart, Workaholic
Run Code Online (Sandbox Code Playgroud)
返回其中一个属性和总属性数也是可以接受的.
查询应该是高效的:人员表中有数百万行,属性表中有数十万行(因此大多数人没有属性).一次选择数百行.
有什么办法吗?
这里有一个菜鸟.
我有一个个人Macbook,我想使用Git来跟踪更改等.我想在我的macbook上创建一个repo并在那里工作.这是一个好主意吗?
如果:我在Macbook HD中的某个地方有一个主要的回购,/Users/user/projects/project1并将其克隆到我实际开发的macbook上的另一个区域?但是这里存在很多冗余.
我有点困惑,想知道人们在类似的个人开发环境中采取的常规步骤.
非常感谢.
此代码无法编译.我想知道我做错了什么:
private static Importable getRightInstance(String s) throws Exception {
Class<Importable> c = Class.forName(s);
Importable i = c.newInstance();
return i;
}
Run Code Online (Sandbox Code Playgroud)
其中Importable是接口,字符串s是实现类的名称.编译器说:
./Importer.java:33: incompatible types
found : java.lang.Class<capture#964 of ?>
required: java.lang.Class<Importable>
Class<Importable> c = Class.forName(format(s));
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
所有的解决方案
Class<? extends Importable> c = Class.forName(s).asSubclass(Importable.class);
Run Code Online (Sandbox Code Playgroud)
和
Class<? extends Importable> c = (Class<? extends Importable>) Class.forName(s);
Run Code Online (Sandbox Code Playgroud)
和
Class<?> c = Class.forName(format(s));
Importable i = (Importable)c.newInstance();
Run Code Online (Sandbox Code Playgroud)
给出这个错误(我不明白):
Exception in thread "main" java.lang.IncompatibleClassChangeError: class C1
has interface Importable as super class
Run Code Online (Sandbox Code Playgroud)
其中C1实际上是实现可导入的(因此它理论上可以转换为可导入的).
我知道核心动画中有某种动画分组机制.那么就说我有两个CABasicAnimation firstAnimation和secondAnimation.我将如何对这些进行分组以及如何启动该组以开始制作动画?
我想我必须将CGRect转换为一个对象以将其传递给fromValue?
这是我尝试的方式,但它不起作用:
CABasicAnimation *frameAnimation = [CABasicAnimation animationWithKeyPath:@"frame"];
frameAnimation.duration = 2.5;
frameAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
frameAnimation.fromValue = [NSValue valueWithCGRect:myLayer.frame];
frameAnimation.toValue = [NSValue valueWithCGRect:theNewFrameRect];
[myLayer addAnimation:frameAnimation forKey:@"MLC"];
Run Code Online (Sandbox Code Playgroud) 一段时间以来我一直在想的一个简单的问题; CPU是否以原子方式分配值,或者是逐位分配值(例如,32位整数).
如果它是一点一滴的,访问这个确切位置的另一个线程是否可以获得待分配值的"部分"?
想一想:
我有两个线程和一个共享的"unsigned int"变量(称之为"g_uiVal").
两个线程循环.
On正在使用printf("%u \n",g_uiVal)打印"g_uiVal".
第二个只是增加这个数字.
打印线程是否会打印出完全不属于"g_uiVal"值的部分?
在代码中:
unsigned int g_uiVal;
void thread_writer()
{
g_uiVal++;
}
void thread_reader()
{
while(1)
printf("%u\n", g_uiVal);
}
Run Code Online (Sandbox Code Playgroud) 每当我尝试序列化字典时,我都会得到异常:
System.ArgumentException: Type
'System.Collections.Generic.Dictionary`2[[Foo.DictionarySerializationTest+TestEnum, Foo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'
is not supported for serialization/deserialization of a dictionary,
keys must be strings or object
Run Code Online (Sandbox Code Playgroud)
我的测试用例是:
public class DictionarySerializationTest
{
public enum TestEnum { A, B, C }
//tried with numbers, too: public enum TestEnum { A = 1, B = 2, C = 3 }
public void SerializationTest()
{
Dictionary<TestEnum, Int32> data = new Dictionary<TestEnum, Int32>();
data.Add(TestEnum.A, 1);
data.Add(TestEnum.B, 2);
data.Add(TestEnum.C, 3);
JavaScriptSerializer serializer = new JavaScriptSerializer();
String …Run Code Online (Sandbox Code Playgroud) 我有以下情况:
class A { public static $arr=array(1,2); }
class B extends A { public static $arr=array(3,4); }
Run Code Online (Sandbox Code Playgroud)
有没有什么办法,以这2个阵,因此结合B::$arrIS 1,2,3,4?
我不需要改变这些数组,但我不能声明它们是als const,因为PHP不允许使用const数组./sf/
PHP手册指出,我只能分配字符串和常量,因此parent::$arr + array(1,2)不起作用,但我认为应该可以这样做.
c ×2
iphone ×2
java ×2
c# ×1
cpu ×1
database ×1
dictionary ×1
eclipselink ×1
generics ×1
git ×1
group-concat ×1
inheritance ×1
join ×1
jpa ×1
json ×1
mysql ×1
php ×1
reflection ×1
sql ×1
try-catch ×1