在构造函数中包含很多参数是错误的吗?像10到15个参数?因为我正在设计一个类,其中构造函数将具有许多参数,例如,一个Person类.
我的示例person类在其构造函数中有6个参数:
public class Person {
private String fName;
private String lName;
private String mInitial;
private int age;
private String contactNumber;
private String emailAddress;
public Person(String fName, String lName, String mInitial, int age, String contactNumber, String emailAddress) {
//insert rest of code here
}
}
Run Code Online (Sandbox Code Playgroud)
那是错的吗?为构造函数创建大量参数?
然后我打算创建一个名为class的类Employee,然后将它扩展到person类,然后它也会有一个很长的构造函数.
令我担心的是实践,这是好还是什么?还有其他建议吗?
每个HTTP请求是否访问相同的servlet对象但是在不同的线程中?或者它是否创建了一个新的线程和新的Servlet实例?
我的代码检索与用户相关的所有信息:
SessionFactory sessionFactory = HibernateUtilities.configureSessionFactory();
Session session = sessionFactory.openSession();
UserDetails ud = null;
Set<Address> userAddress = null;
try {
session.beginTransaction();
ud = (UserDetails) session.get(UserDetails.class, 1);
userAddress = ud.getAddresses();
session.getTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
session.getTransaction().rollback();
} finally {
session.close();
}
System.out.println(ud.getName());
for(Address addr: userAddress){
System.out.println("State " + addr.getState());
}
Run Code Online (Sandbox Code Playgroud)
在ud.getAddresses()简单地返回一组Address用户的ES.
我的问题是:ud即使会话已经关闭,为什么对象仍然具有其值(例如,名称)?getAddresses()是类的实例变量UserDetails.但为什么我不能检索它的值,但我可以检索UserDetails该类的常规实例变量?
ud.getAddresses()是一个@EmbeddedCollection.
java persistence hibernate lazy-evaluation lazy-initialization
如何实现html5音频标签的闪回后备?例如,我有这个音频标签
<div class = "div.jp-audio"><audio class ="audio-player" name= "audio-player" src="song.mp3" ></audio></div>
Run Code Online (Sandbox Code Playgroud)
由于并非所有浏览器都支持.mp3文件,因此如何启用或创建闪回功能
我这里的代码使用struts2-jquery插件
<h4>Choose A task</h4>
<ul>
<s:url value="views/ajaxvalidation.jsp" var="ajaxvalidation" >
<s:param name="menuId" value="1"/>
</s:url>
<li><sj:a targets="resultContent" href="%{ajaxvalidation}">Ajax Validation</sj:a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
当我点击它的内容时,网址会改变为这样的内容,网址中没有任何变化.它仍然保持不变,我想要的是当我点击链接时会发生类似这样的事情www.myapp.com/#ajaxvalidation.当我运行代码时,锚标签被翻译成这样的东西
<a id="anchor_1365013162" href="javascript:void(0)">Ajax Validation</a>
Run Code Online (Sandbox Code Playgroud)
有了这个,我将如何在网址中添加哈希?
我正在编写一个需要加密密码的注册表,我听说建议我使用Blowfish加密密码,如何使用PHP crypt()函数实现blowfish加密?另外,我打算稍后检索密码以便登录.
我有这门课
public class Tree<T> {
//List of branches for this tree
private List<Tree<? super T>> branch = new ArrayList<Tree<? super T>>();
public Tree(T t){ this.t = t; }
public void addBranch(Tree< ? super T> src){ branch.add(src); }
public Tree<? extends T> getBranch(int branchNum){
return (Tree<? extends T>) branch.get(branchNum);
}
private T t;
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用此类创建一个变量
public static void main(String[] args){
Tree<? super Number> num2 = new Tree<? super Number>(2);
}
Run Code Online (Sandbox Code Playgroud)
它给了我这个错误
Cannot instantiate the type Tree<? super Number>
Run Code Online (Sandbox Code Playgroud) 我正在通过Ajax加载页面.当用户单击链接时,页面正在成功加载AJAX,但是当用户单击后退按钮时,页面将重新加载初始页面.所以场景就是这样.
这是标记.
$(function() {
// Prepare
var History = window.History; // Note: We are using a capital H instead of a lower h
if (!History.enabled) {
// History.js is disabled for this browser.
// This is because we can optionally choose to support HTML4 browsers or not.
return false;
}
// Bind to StateChange Event
History.Adapter.bind(window, 'statechange', function() { // Note: We are using statechange instead of popstate
var State = History.getState();
$('#content').load(State.url);
});
$('a').click(function(evt) …Run Code Online (Sandbox Code Playgroud) 我目前正在学习java,堆栈和堆的内存概念,我知道局部变量和方法调用都存在于一个叫做堆栈的地方.和对象住在堆里面.但是如果该局部变量包含一个对象呢?或者有对象参考?
public void Something(){
Duck d = new Duck(24);
}
Run Code Online (Sandbox Code Playgroud)
它仍然存在于堆栈中吗?实例变量在哪里生活?请尽量保持简单.谢谢.
给出这段代码片段
//Creates a list of List numbers
List<List<Number>> num = new ArrayList<List<Number>>();
//Creates a list of List doubles
List<List<Double>> doub = new ArrayList<List<Double>>();
//List of doubles
List<Double> d = new ArrayList<Double>();
d.add(2.5);
d.add(2.6);
doub.add(d);
num.add(d);//This code will not compile
Run Code Online (Sandbox Code Playgroud)
为什么不允许num.add(doub)?不是List<List<Number>>超级型
List<List<Double>>?
java ×6
ajax ×2
generics ×2
javascript ×2
jquery ×2
wildcard ×2
audio ×1
blowfish ×1
constructor ×1
flash ×1
heap ×1
hibernate ×1
history.js ×1
html5 ×1
http ×1
inheritance ×1
jvm ×1
parameters ×1
pecs ×1
persistence ×1
php ×1
request ×1
security ×1
servlets ×1
struts2 ×1
url ×1