两种方法都有任何优势吗?
例1:
class A {
B b = new B();
}
Run Code Online (Sandbox Code Playgroud)
例2:
class A {
B b;
A() {
b = new B();
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个网站,当我用谷歌插件检查页面速度时,我收到:
利用浏览器缓存
以下资源缺少缓存过期
搜索仅返回在Apache下使用htaccess的信息,但我的站点在Windows 2003 Server上以纯HTML语言运行,我甚至无法访问服务器.
是否有任何方法来指定expiration和gzip压缩,因为它建议?
我想了解这段代码:
while row = input.gets
row.strip!
next if row.empty?
valuesplit = row.split("---")
a, b = valuesplit[1..2]
unless a == b
$hash1[a] ||= {} <--------------What is this line doing? How is the whole loop
$hash1[a][b] = true being traversed?
if $hash1[b] && $hash1[b][a] <-----Can you please describe this if() loop
$hash2[a] ||= []
$hash2[a] << b
$hash2[b] ||= []
$hash2[b] << a
end
end
end
Run Code Online (Sandbox Code Playgroud)
注意:$ hash1 = {} $ hash2 = {}
谢谢!
UPDATE
输入:
junkdata1 value1 value2
junkdata2 value3 …Run Code Online (Sandbox Code Playgroud) 在SQL 2005服务器数据库上实现树结构时,当使用LIKE子句与EXISTS子句结合使用时,查询响应时间过长(查询超过5秒).
慢查询涉及两个表 - [SitePath_T]和[UserSiteRight_T]:
CREATE TABLE [dbo].[UserSiteRight_T](
[UserID_i] [int] NOT NULL
, [SiteID_i] [int] NOT NULL
, CONSTRAINT [PKC_UserSiteRight_UserIDSiteID] PRIMARY KEY CLUSTERED ( [UserID_i] ASC, [SiteID_i] ASC )
, CONSTRAINT [FK_UserSiteRight_UserID] FOREIGN KEY( [UserID_i] ) REFERENCES [dbo].[User_T] ( [ID_i] )
, CONSTRAINT [FK_UserSiteRight_SiteID] FOREIGN KEY( [SiteID_i] ) REFERENCES [dbo].[Site_T] ( [ID_i] )
)
Run Code Online (Sandbox Code Playgroud)
行(总数权利),用于UserID_i = 2484在[UserSiteRight_T]表是相当小:545
(UserID_i = 2484被随机选择的)
此外,数据库相对较小 - [SitePath_T]表中只有23000行:
CREATE …Run Code Online (Sandbox Code Playgroud) 我试图使用此代码建议(http://www.daniweb.com/forums/thread23883.html#)将控制台输出写入txt文件但是我没有成功.怎么了?
try {
//create a buffered reader that connects to the console, we use it so we can read lines
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//read a line from the console
String lineFromInput = in.readLine();
//create an print writer for writing to a file
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
//output to the file a line
out.println(lineFromInput);
//close the file (VERY IMPORTANT!)
out.close();
}
catch(IOException e1) {
System.out.println("Error during reading/writing");
}
Run Code Online (Sandbox Code Playgroud) 我正在将静态库(assimp)合并到现有项目(Spring RTS)中,其中库和项目都在定期开发中.我正在尝试以这样的方式添加库,以便在新版本发布时我可以轻松地重复集成.
无论如何,问题是Spring要求库使用streflop数学库执行所有数学运算.在实践中,这种方法min(x,y)应该被替换为所使用的streflop::min(x,y)任何地方(考虑到该问题适用于所有数学函数,这意味着很多).
我可以做一个大规模的正则表达式替换,但我希望有一些更优雅的东西.经过一些研究和测试后,似乎using namespace streflop;在每个.cpp文件的顶部添加可以做到这一点,但事实并非如此.
确切的错误是:
/mnt/work/workspace/spring-patch-git/spring/rts/lib/assimp/code/FixNormalsStep.cpp:147: error: call of overloaded sqrtf(const float&) is ambiguous
/usr/include/bits/mathcalls.h:157: note: candidates are: float sqrtf(float)
/mnt/work/workspace/spring-patch-git/spring/rts/lib/streflop/SMath.h:347: note: streflop::Simple streflop::sqrtf(streflop::Simple)
Run Code Online (Sandbox Code Playgroud)
我认为名称空间的全部意义在于解决这类问题,但它似乎并不适用于此.我对streflop :: Simple的引用感到有些困惑.这是一个嵌套的命名空间,这可能是它没有按预期工作的部分原因吗?
是否有一些资源可以解决多线程问题?如果可能的话,想向受访者提出这些建议.厌倦了询问相同的等待通知问题,这些问题每个人现在都是正确的,但无法想象出采用多线程的真实场景.
如果我有一个用户可以标记另一个用户帖子并且无法撤消或更改的网站,我是否需要拥有主键?我的所有选择都在post_id上,并带有where子句以查看用户是否已标记它.
我不知道如何使用/创建oop代码而不使用静态字.我阅读了Sun教程,有书和例子.我知道有构造函数,然后"指针"这个等我可以使用return语句创建一些简单的非静态方法.真正的问题是,我只是不明白它是如何工作的.我希望有些沟通能让我继续前进.如果有人问,这不是功课.我只是想学习如何编码.以下代码是静态方法和一些非常基本的算法.我想知道如何使用逻辑步骤将其更改为非静态代码(请.).第二个代码显示了一些我可以编写但不完全理解的非静态代码,也不会将其用作模板来重写第一个代码.提前感谢任何提示.
import java.util.Scanner;
/**
*
* @author
*/
public class NumberArray2{
public static int[] table() {
Scanner Scan = new Scanner(System.in);
System.out.println("How many numbers?");
int s = Scan.nextInt();
int[] tab = new int[s];
System.out.println("Write a numbers: ");
for(int i=0; i<tab.length; i++){
tab[i] = Scan.nextInt();
}
System.out.println("");
return tab;
}
static public void output(int [] tab){
for(int i=0; i<tab.length; i++){
if(tab[i] != 0)
System.out.println(tab[i]);
}
}
static public void max(int [] tab){
int maxNum = 0;
for(int i=0; i<tab.length; i++){
if(tab[i] …Run Code Online (Sandbox Code Playgroud) 我正试图在eclipse 3.5中运行一些JUnit测试单元,但根本没有运气.
JUnit3工作正常.
当我创建JUnit4测试单元时,eclipse提供将JUnit库添加到类路径中.我接受了,但当我检查它是否已添加到项目的属性面板中时,我可以看到添加了JUnit4,但没有包含JARS.
如果我选择编辑,组合会说"JUnit 4",就在"当前位置:未找到"之下.
当我启动JUnit4测试时,出现错误并发生内部错误,NullPointerException.
我已经阅读了大约两天了,所有的引用都说eclipse包含JUnit4,但不知怎的,似乎有些东西我不见了.
我已经尝试重新创建我的项目,并在没有运气的情况下创建全新的测试.
package test;
import static org.junit.Assert.*;
import org.junit.Test;
public class AuthServiceTest {
@Test
public final void testValidateCredentials() {
fail("Not yet implemented"); // TODO
}
}
Run Code Online (Sandbox Code Playgroud)
[编辑]我已经将junit-4.8.1.jar添加到项目的类路径和eclipe的类路径中,但仍然是同样的问题.[Edit2]我还添加了junit-dep-4.8.1.jar,因为我不确定这些依赖项是否必要,但没有变化.
java ×5
c++ ×1
console ×1
constructor ×1
dynamic ×1
eclipse ×1
file-io ×1
html ×1
http-caching ×1
iis ×1
junit ×1
namespaces ×1
ruby ×1
sql ×1
sql-server ×1