有没有办法在提交时删除Intellij IDEA中未使用的导入?
手动完成它并不是最理想的,CTRL+ ALT+有O帮助,但它仍然是手动的.
我知道如何通过执行以下操作为名称已知的属性创建getter和setter:
// A trivial example:
function MyObject(val){
this.count = 0;
this.value = val;
}
MyObject.prototype = {
get value(){
return this.count < 2 ? "Go away" : this._value;
},
set value(val){
this._value = val + (++this.count);
}
};
var a = new MyObject('foo');
alert(a.value); // --> "Go away"
a.value = 'bar';
alert(a.value); // --> "bar2"
Run Code Online (Sandbox Code Playgroud)
现在,我的问题是,是否有可能定义这些全能的吸气剂和定型器?即,创建getter和setter的任何属性名称是不是已经定义.
这个概念可以在PHP中使用__get()和__set()魔术方法(请参阅PHP文档以获取有关这些的信息),所以我真的要问是否有与这些相当的JavaScript?
不用说,我理想地喜欢跨浏览器兼容的解决方案.
我有授权SSL连接的问题.我创建了Struts Action,它通过Client Authorized SSL证书连接到外部服务器.在我的行动中我试图将一些数据发送到银行服务器但没有任何运气,因为我从服务器得到以下错误的结果:
error: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
Run Code Online (Sandbox Code Playgroud)
我的Action类从我的Action类发送数据到服务器
//Getting external IP from host
URL whatismyip = new URL("http://automation.whatismyip.com/n09230945.asp");
BufferedReader inIP = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
String IPStr = inIP.readLine(); //IP as a String
Merchant merchant;
System.out.println("amount: " + amount + ", currency: " + currency + ", clientIp: " + IPStr + ", description: " + description);
try {
merchant = new Merchant(context.getRealPath("/") + "merchant.properties");
} catch (ConfigurationException e) {
Logger.getLogger(HomeAction.class.getName()).log(Level.INFO, "message", e);
System.err.println("error: " + e.getMessage());
return …Run Code Online (Sandbox Code Playgroud) 为什么181783497276652981和8682522807148012在选择Random.java?
这是Java SE JDK 1.7的相关源代码:
/**
* Creates a new random number generator. This constructor sets
* the seed of the random number generator to a value very likely
* to be distinct from any other invocation of this constructor.
*/
public Random() {
this(seedUniquifier() ^ System.nanoTime());
}
private static long seedUniquifier() {
// L'Ecuyer, "Tables of Linear Congruential Generators of
// Different Sizes and Good Lattice Structure", 1999
for (;;) {
long current …Run Code Online (Sandbox Code Playgroud) 刚刚下载了基于Intellij Idea的Android Studio.
如何创建测试?
我注意到有一个创建测试模块的选项,但这似乎没有做任何事情,只用src创建一个新项目
我也尝试按热键CTRL + AlT + T,它允许在现有类上创建单元测试,但它似乎想将它放在当前项目中.当然这对TDD没有帮助
有没有人有这方面的经验?
当我在控制台上运行演示JSF应用程序时,我收到以下错误
[SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:JSFTut' did not find a matching property.
Run Code Online (Sandbox Code Playgroud) 我的Java测试在Eclipse中运行良好.但现在,当我从运行菜单重新启动测试时,我收到以下消息:
No tests found with test runner 'JUnit 4'
Run Code Online (Sandbox Code Playgroud)
在.classpath文件中我有所有jar文件,最后有:
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Run Code Online (Sandbox Code Playgroud)
如何解决此错误并让测试再次运行?
我有一个JAR文件,我需要获取此JAR文件中所有类的名称.我怎样才能做到这一点?
我搜索了它,看到了一些关于JarFile或Java的东西,ClassLoader但我不知道该怎么做.
在设计API时我可以遵循哪些准则和最佳实践?至少,我知道API应该易于使用且灵活.不幸的是,这些术语可能相当主观,因此我正在寻找一些与良好API设计相关的具体指导原则.
在Java中,private访问修饰符被认为是安全的,因为它在类之外是不可见的.然后外界也不知道那种方法.
但我认为Java反射可以用来打破这个规则.考虑以下案例:
public class ProtectedPrivacy{
private String getInfo(){
return "confidential";
}
}
Run Code Online (Sandbox Code Playgroud)
现在从另一个班级我将获得信息:
public class BreakPrivacy{
public static void main(String[] args) throws Exception {
ProtectedPrivacy protectedPrivacy = new ProtectedPrivacy();
Method method = protectedPrivacy.getClass().getDeclaredMethod("getInfo", null);
method.setAccessible(true);
Object result = method.invoke(protectedPrivacy);
System.out.println(result.toString());
}
}
Run Code Online (Sandbox Code Playgroud)
此时我只是认为私有方法安全,因为做上面的事情我们必须知道方法名称.但是如果包含由其他人编写的私有方法的类我们没有那些可见性.
但是,由于下面的代码行,我的观点变得无效.
Method method[] = new ProtectedPrivacy().getClass().getDeclaredMethods();
Run Code Online (Sandbox Code Playgroud)
现在这method[]包含了上面需要做的所有事情.我的问题是,有没有办法避免使用Java反射这类事情?
我引用Java文档中的一些观点来澄清我的问题.
选择访问级别的提示:
如果其他程序员使用您的类,您希望确保不会发生滥用错误.访问级别可以帮助您执行此操作.使用对特定成员有意义的最严格的访问级别.除非你有充分的理由不使用私人.
java ×7
eclipse ×2
android ×1
api ×1
api-design ×1
automation ×1
class ×1
classloader ×1
file ×1
import ×1
jar ×1
javascript ×1
junit ×1
junit4 ×1
private ×1
random ×1
reflection ×1
ssl ×1
tomcat ×1
unit-testing ×1