我一直在阅读关于finalize()的很多新手Java问题,并发现有点令人困惑的是,没有人真正说明finalize()是一种不可靠的清理资源的方法.我看到有人评论说他们用它来清理Connections,这真的很可怕,因为接近Connection的关闭的唯一方法就是最终实现try(catch).
我没有受过CS的教育,但是我已经用Java专业编程近十年了,我从未见过有人在生产系统中实现finalize().这仍然不意味着它没有它的用途,或者我与之合作过的人一直在做正确的事.
所以我的问题是,实现finalize()的用例是什么,无法通过语言中的其他进程或语法更可靠地处理?
请提供具体的方案或您的经验,只是重复Java教科书,或最终确定的用途是不够的,这不是这个问题的意图.
假设我有'abbc'字符串,我想替换:
如果我尝试两次替换,结果不是我想要的:
echo 'abbc' | sed 's/ab/bc/g;s/bc/ab/g'
abab
Run Code Online (Sandbox Code Playgroud)
那么我可以使用什么sed命令替换如下?
echo abbc | sed SED_COMMAND
bcab
Run Code Online (Sandbox Code Playgroud)
编辑:实际上文本可能有两个以上的模式,我不知道我需要多少替换.既然有一个答案说这sed
是一个流编辑器并且它的替换是贪婪的,我认为我需要使用一些脚本语言.
我是我公司产品的最终用户.它不太适合集成到Spring中,但是我能够处理上下文并按名称检索所需的bean.但是,我仍然想知道是否有可能将bean注入到这个类中,即使该类不是由Spring本身管理的.
澄清:管理某些类MyClass生命周期的同一个应用程序也在管理Spring上下文的生命周期.Spring对MyClass的实例没有任何了解,我想知道如何将实例提供给上下文,但不能在上下文本身中创建实例.
我生成了一个JTW令牌,并且有一些我很清楚的声明,但是kid
在标题中有一个声明.有谁知道这意味着什么?
我使用auth0.com生成令牌
我试图调整maven插件执行将在maven-2中运行的阶段.
我的具体问题是尝试运行cobertura:instrument
绑定到生命周期阶段的步骤process-test-classes
,以便它不会与使用aspectj的其他插件冲突(并删除检测代码,从而生成0%的覆盖率报告).但我的问题更通用.
在deafault生命周期内,我通过在插件声明中添加一个执行部分来实现这一目标:
<build>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>instrument-late</id>
<phase>process-test-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
</plugin>
...
Run Code Online (Sandbox Code Playgroud)
这样,当我运行mvn test
一切正常时,cobertura:仪器在我想要的阶段运行,类得到检测,测试运行与检测类等等.这是汇总输出:
[INFO] [clean:clean {execution: default-clean}]
[INFO] [buildnumber:create {execution: default}]
[INFO] [native2ascii:native2ascii {execution: native2ascii-utf8}]
[INFO] [native2ascii:native2ascii {execution: native2ascii-8859_1}]
[INFO] [resources:resources {execution: default-resources}]
[INFO] [compiler:compile {execution: default-compile}]
[INFO] [jar:jar {execution: lib}]
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Preparing hibernate3:hbm2ddl
[WARNING] Removing: hbm2ddl from forked lifecycle, to prevent recursive invocation.
[INFO] [buildnumber:create {execution: default}]
[INFO] Change …
Run Code Online (Sandbox Code Playgroud) 自从我为maven安装了新的m2e插件后,我的Groovy项目不再构建.我正在使用这里描述的groovy-compiler-plugin .我得到maven-compiler-plugin的旧"插件执行未涵盖..."错误.我已经尝试了执行和忽略目标"testCompile"和"编译",如错误中所述.
由于一些神秘的编译器问题,我无法使用GMaven.由于我公司的构建过程,我也被Maven 2.2.1锁定了.旧的m2eclipse插件已经不见了,m2e的文档非常糟糕.
我对此有所了解.我没有其他地方看到这个问题.我不可能是唯一一个.
如果我很快就找不到这个解决方案,我要么为了一些黑客Gradle实现而废弃maven(虽然我也不能使用它),或者我正在转向NetBeans,这不是一个成功的命题.
根据要求,pom片段在下面.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/groovy</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/groovy</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>true</verbose>
<source>1.6</source>
<target>1.6</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>1.8.0-03</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.5.1</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store …
Run Code Online (Sandbox Code Playgroud) 我有一个maven 3项目.在POM中,我定义了许多<properties>
- 一些在下<project>
,另一些在特定之下<profile>
.是maven中将所有声明的属性导出到.properties文件的方法吗?
我目前的做法是:
myProp=${myProp}
似乎应该有一种方法来消除上面的第2步......
谢谢,-nikita
我最近尝试使用Apache Commons-Configuration来管理一些本地XML配置文件.它大大降低了易用性(无法加载空配置文件,CombinedConfiguration需要利用大多数操作的底层配置等),以及其API的一致性(保存操作帖子没有事件,事件不是通用的).
除了写入注册表的JDK首选项(我不想要),还有其他替代方法来管理基于文件的首选项吗?
使用其他文件格式不是一种选择.
我们已经实现了一个自定义验证器。
我们收到了正常的消息,但没有收到 propertyPath,我们怎样才能把它拉回来呢?
在我们的对象中实现
@RequiredIfSet.List({
@RequiredIfSet(propertyPath = "reporterFirstName", field = "isFillingOutForSomeoneElse", dependentField = "reporterFirstName", message = "Reporter First may not be null"),
@RequiredIfSet(propertyPath = "reporterLastName", field = "isFillingOutForSomeoneElse", dependentField = "reporterLastName", message = "Reporter Last may not be null"),
@RequiredIfSet(propertyPath = "reporterContactPhone", field = "isFillingOutForSomeoneElse", dependentField = "reporterContactPhone", message = "Reporter Contact Phone may not be null"),
@RequiredIfSet(propertyPath = "reporterEmail", field = "isFillingOutForSomeoneElse", dependentField = "reporterEmail", message = "Reporter Email may not be null")
})
Run Code Online (Sandbox Code Playgroud)
//约束类
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) …
Run Code Online (Sandbox Code Playgroud)