任何人都可以告诉我在java中使用main方法作为final.
虽然这在java中是允许的
public static final void main(String[] args) {
}
Run Code Online (Sandbox Code Playgroud)
我没有看到任何使用它最终的用途.无论如何它是静态的,所以我们不能覆盖它.
java中类的命名约定是什么,例如,所有类都应该是大写,如MYCLASS.java?
像com.sun.org.apache.bcel.internal.generic这样的一些类 .ANEWARRAY.也可以在Sun的图书馆找到
注意:我已经阅读了Oracle的所有命名约定,但我找不到任何说明我们应该使用All Uppercase命名一个类.
您好我已经从wsdl文件在eclipse中创建了一个Web服务客户端.但当我尝试从客户端访问该服务时,它说.没有可用于端点的SSL配置.然后我的端点的地址.请告诉我如何通过密钥库向我的webservice客户端提供ssl配置.我有客户端提供的独立客户端和密钥库.TIA
我有一个场景,我必须设置一个模拟对象的属性,如下所示:
SlingHttpRequest slingHttpRequest= mock(SlingHttpRequest);
slingHttpRequest.setAttribute("search", someObject);
Run Code Online (Sandbox Code Playgroud)
当我尝试打印此属性时,我得到了null.我该如何设置此属性?
Java规范统计数据
序列化运行时将每个可序列化类与版本号相关联,称为serialVersionUID,在反序列化期间使用该版本号来验证序列化对象的发送方和接收方是否已加载与该序列化兼容的该对象的类.如果接收者为具有与相应发送者类的serialVersionUID不同的对象加载了一个类,则反序列化将导致InvalidClassException.
enter code here
但是,如果我为所有类分配相同的串行版本ID,如下所示
static final long serialVersionUID = 1L;
Run Code Online (Sandbox Code Playgroud)
现在我的所有类都将具有相同的serialversionUID,这将永远不会导致InvalidclassException.
我知道我们明确地给它,以便它的值在不同的JVM实现中保持不变.
请让我知道在所有类中使用相同的id有什么用,如果我们在序列化和反序列化之间修改类会发生什么?
我在春天使用程序化事务管理,现在我已经切换到声明式事务管理.
SessionFactory的
<beans:bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="packagesToScan" value="com.hcentive.cig.domain" />
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.hbm2ddl.auto">update</beans:prop>
<beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
</beans:prop>
<beans:prop key="hibernate.show_sql">true</beans:prop>
<beans:prop key="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
Run Code Online (Sandbox Code Playgroud)
事务管理
<beans:bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory">
<beans:ref bean="sessionFactory" />
</beans:property>
</beans:bean>
Run Code Online (Sandbox Code Playgroud)
现在如果运行我的代码
@Override
@Transactional
public Request saveRequest(Request request) {
sessionFactory.getCurrentSession().save(request);
return request;
}
Run Code Online (Sandbox Code Playgroud)
如果没有活动事务,我会收到异常保存无效
如果我删除下面的行
<beans:prop key="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</beans:prop>
Run Code Online (Sandbox Code Playgroud)
我明白了
没有配置CurrentSessionContext!
我知道如果我需要模拟静态方法,这表明我的设计有一些问题,但在我的情况下,这似乎不是一个设计问题.
BundleContext bundleContext = FrameworkUtil.getBundle(ConfigService.class).getBundleContext();
Run Code Online (Sandbox Code Playgroud)
这里FrameworkUtil是一个存在于api jar中的类.在代码中使用它不能成为一个设计问题.
我的问题在于运行此行
FrameworkUtil.getBundle(ConfigService.class);
Run Code Online (Sandbox Code Playgroud)
返回null所以我的问题是,有什么方法可以在运行时替换null我使用Mockito framewrok并且我的项目不允许我使用powermock.
如果我使用
doReturn(bundle).when(FrameworkUtil.class)
Run Code Online (Sandbox Code Playgroud)
这样,getBundle方法因其静态方法而不可见.
我有一个while循环如下
while (nodeIterator.hasNext())
Run Code Online (Sandbox Code Playgroud)
我已经模拟了这个方法hasNext返回true,以便我可以在while循环中测试代码但现在问题是每次它返回true并且这个循环永远不会结束.请告诉我,无论如何我可以确保只调用一次这个方法,如果没有,那么在第一次执行后如何返回false
我有两种方法如下
public void add(List<String> strs) {...}
public void add(List<Integer> ints) {...}
Run Code Online (Sandbox Code Playgroud)
我得到编译错误,所以我的问题是为什么这不会重载,那么使用泛型的优势是什么呢?
这是我得到的错误:
Method add(List<Integer>) has the same erasure add(List<E>) as another method in type Child
Run Code Online (Sandbox Code Playgroud) 我遇到了一个问题,我无法找出其输出为什么会出现的问题
7
当我以数学方式计算它可以产生7,8或任何其他数字的输出所以我的问题是它的基础是什么
interface InterfaceA
{
int A = InterfaceB.B * 2;
}
interface InterfaceB
{
int B = InterfaceC.C + 1;
}
interface InterfaceC extends InterfaceA
{
int C = A + 1;
}
public class TestInterface implements InterfaceA, InterfaceB, InterfaceC {
public static void main(String[] args) {
System.out.println(A + B + C);
}
}
Run Code Online (Sandbox Code Playgroud) 我有这样的场景
InputStreamReader reader = new InputStreamReader(getFileAsStream(resourceResolver, iconpath));
BufferedReader bReader = new BufferedReader(reader);
Run Code Online (Sandbox Code Playgroud)
我一直嘲笑到这一点
getFileAsStream(resourceResolver, iconpath)
Run Code Online (Sandbox Code Playgroud)
现在我有一个读者
BufferedReader bReader = new BufferedReader(reader);
Run Code Online (Sandbox Code Playgroud)
但是当我执行这一行时,我得到null并且无法前进
while ((iconEntry = bReader.readLine()) != null)
Run Code Online (Sandbox Code Playgroud)
请告诉我怎么嘲笑这个.请注意我无法更改我的主要代码,因此Mockito docs上的解决方案在我的情况下无效
测试代码
@RunWith(PowerMockRunner.class)
@PrepareForTest({ FrameworkUtil.class, LoggerFactory.class })
public class IconPreviewServletTest {
private IconPreviewServlet iconPreviewServlet;
private SlingHttpServletRequest request;
private SlingHttpServletResponse response;
private Bundle bundle;
private BundleContext bundleContext;
private ServiceReference factoryRef;
private CommonService resolverFactory;
private PrintWriter out;
private ResourceResolver resourceResolver;
private Resource resource;
private Node node;
private Node jcrContent;
private javax.jcr.Property property;
private …Run Code Online (Sandbox Code Playgroud)