我有一个关于封装的问题.据我所知,封装允许使用私有/受保护数据成员隐藏实现细节,并提供操作数据的公共方法和属性.这里的想法是防止类消费者直接修改数据成员.
但我对属性getter或其他返回私有/受保护数据成员的公共方法感到担忧.例如:如果我有这样的课程
public class Inventory
{
private List<Guitar> guitars = new List<Guitar>();
public void AddGuitar(string serialnumber, string price)
{
Guitar guitar = new Guitar(serialnumber, price);
guitars.Add(guitar);
}
public List<Guitar> GetGuitars()
{
return guitars;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,如果Inventory类消费者调用GetGuitars,他将获得在Inventory类中维护的吉他列表.现在,消费者可以修改列表,例如删除/添加/修改项目.对我来说,看起来我们没有封装.我想我应该在GetGuitars()中返回吉他列表项的副本.你怎么看?.
我对封装的理解是对的吗?
谢谢
简单。这是Maven pom.xml中的felix插件:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- allows the route to be ran via 'mvn camel:run' -->
<!-- <plugin> <groupId>org.apache.camel</groupId> <artifactId>camel-maven-plugin</artifactId>
<version>2.10.1</version> </plugin> -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>xyz</Bundle-SymbolicName>
<Export-Package>tutorial.simplerouter</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>`
Run Code Online (Sandbox Code Playgroud)
并且它不能正确生成MANIFEST.MF文件:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: rb
Build-Jdk: 1.6.0_35
Run Code Online (Sandbox Code Playgroud)
上面生成的manifest.mf不正确。
请告诉我为什么。
在尝试运行我的网络应用程序时,我收到了下面提到的错误.以前我的应用程序运行正常.但今天我给了maven干净,然后尝试通过给maven目标作为tomcat来运行它:运行,我收到此错误
[INFO]
[INFO] BUILD FAILURE
[INFO]
[INFO] Total time: 6.754s
[INFO] Finished at: Tue Mar 11 15:09:44 IST 2014
[INFO] Final Memory: 11M/28M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:run (default-cli) on project metaDB: Could not start Tomcat: Memory database file
D:\WORK\target\tomcat\conf\tomcat-users.xml cannot be read -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
Run Code Online (Sandbox Code Playgroud)
请帮助解决这个问题.
我成功安装了Ambari服务器,但当我尝试启动该服务器时,它说,
/bin/sh: /usr/jdk64/jdk1.7.0_45/bin/java: cannot execute binary file
Run Code Online (Sandbox Code Playgroud)
那么请你帮我解决这个问题.
谢谢.
我对在 Apache Tomcat 上的 Spring 框架中使用 JTA 有一些困惑,我希望有人能澄清,因为经过多次研究,我似乎还无法找到正确的答案。
我正在使用 Spring Framework 开发一个在 Apache Tomcat 6 上运行的 Web 应用程序。
我在某处读到 Spring 确实支持 JTA,但它委托给底层 JavaEE 应用程序服务器。现在这就是我感到困惑的地方,因为 Tomcat 不是一个完整的 JavaEE 应用程序服务器 - 它只是一个 servlet 容器,并且我相信它不提供像完整的 JavaEE 应用程序服务器(Glassfish/Wildfly 等...)那样的 JTA 实现做。
但是,当我执行以下操作时,它的事务方面会起作用:
@Transactional
public class ServiceClassImpl implements ServiceInterface {
// code here that involves transactions e.g. calling DAO code
...
}
Run Code Online (Sandbox Code Playgroud)
所以,我很困惑。我希望有人能启发我。
我开始学习大数据和Apache Spark,我有一个疑问.
将来我需要从物联网收集数据,这些数据将作为时间序列数据发给我.我正在阅读时间序列数据库(TSDB),我发现了一些开源选项,如Atlas,KairosDB,OpenTSDB等.
我实际上需要Apache Spark,所以我想知道:我可以在Apache Spark上使用时间序列数据库吗?它有意义吗?请记住,我对大数据的概念,Apache Spark以及我在这个问题中谈到的所有问题都很陌生.
如果我可以通过Spark运行TSDB,我该如何实现?
我在Android上使用Cordova 5.1.1实现了一些问题.我正在尝试在我的应用程序中嵌入CordovaWebView.我已按照其官方网站中描述的所有说明操作,但我不断收到错误" org.apache.cordova.CordovaWebView无法转换为android.view.View ".我已经搜索了很多帮助,但我找不到任何可以帮助我的东西.这是我的代码:
活动:
public class CordovaTestActivity extends Activity implements CordovaInterface {
protected CordovaPlugin activityResultCallback = null;
protected boolean activityResultKeepRunning;
protected boolean keepRunning = true;
private final ExecutorService threadPool = Executors.newCachedThreadPool();
CordovaWebView cwv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cordova_test);
cwv = (CordovaWebView) findViewById(R.id.tutorialView);
Config.init(this);
cwv.loadUrl(Config.getStartUrl());
}
@Override
public Activity getActivity() {
return this;
}
@Override
public ExecutorService getThreadPool() {
return threadPool;
}
@Override
public Object onMessage(String arg0, Object arg1) {
return null;
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 如何访问 Apache Camel Rest 模块中的 PathVariables?
我定义了这样的路线(遵循文档中的“使用基本路径” ):
rest("/customers/")
.get("/{id}").to("direct:customerDetail")
Run Code Online (Sandbox Code Playgroud)
如何{id}在以下路线中控制 -Parameter?
基本上我想知道骆驼提供什么而不是@PathVariable(见下面的例子)
@RequestMapping(value="/customers/{id}", method = RequestMethod.GET)
public Customer customerDetail(@PathVariable String cId) {
return getCustomer(cId);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个简单的HttpClient程序.这是我第一次与之合作HttpClient,我很困惑要包括哪些罐子.
当我创建一个对象时,我已经包含了apache-httpcomponents-httpclient.jar和 org.apache.commons.httpclient.jar这些,我HttpClient在客户端对象中看到了不同的方法
package com.comverse.rht;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
public class HttpClientTest {
public static void main(String[] args) throws URIException {
URI url = new URI("http://www.google.com/search?q=httpClient");
HttpClient client = new HttpClient();
GetMethod get = new GetMethod();
PostMethod post = new PostMethod();
String responseString;
StringBuilder sb = new …Run Code Online (Sandbox Code Playgroud) 给定一个数组大小 n 和一个正数 max(max 表示我们可以用来放置在数组中的数字的范围)。
我想计算我可以在数组中放置多少个排序数字组合。
例如 :
如果n = 3, max = 2.(我们可以使用的唯一数字是 1/2,因为最大值是 2)所以排序数组有 4 种组合
1. {1,1,1}
2. {1,1,2}
3. {1,2,2}
4. {2,2,2}
Run Code Online (Sandbox Code Playgroud)
我写了一些代码并成功通过了这个特定的例子,但max > 2没有返回正确答案的任何其他例子。
我发现的问题是当递归到达最后一个索引时,它不会尝试第三个数字,它只是折回。
我的代码:
private static int howManySorted(int n, int max, int index, int numToMax, int prevNum) {
// If the value is bigger then max return 0
if(numToMax > max) {
return 0;
}
if (numToMax < prevNum) {
return 0;
}
//If Index reached the end of …Run Code Online (Sandbox Code Playgroud) java ×6
tomcat ×2
web-services ×2
ambari ×1
android ×1
apache-camel ×1
apache-felix ×1
apache-spark ×1
bigdata ×1
cordova ×1
database ×1
http ×1
jta ×1
maven ×1
oop ×1
recursion ×1
rest ×1
sorting ×1
spring ×1
spring-mvc ×1
time-series ×1