avatar
Apple Siri 组 Java 测试题# JobHunting - 待字闺中
r*r
1
/**
* Using {@link AppleExercise.Problem1.SampleCache} as a starting point,
answer questions 1-3 by
* creating 3 new inner classes within {@link AppleExercise.Problem1}
below.
*/
public static class Problem1 {
public interface Cache {
public void put(Object key, Object value);
public Object get(Object key);
}
public static class SampleCache implements Cache {
private Map map;
public SampleCache() {
map = new HashMap();
}
@SuppressWarnings("unchecked")
public void put(Object key, Object value) {
map.put(key, value);
}
public Object get(Object key) {
return map.get(key);
}
}
/**
* Problem 1.1
*
* Re-implement {@link AppleExercise.Problem1.SampleCache} as a
singleton which implements the Cache interface.
* Do not use any @SuppressWarnings annotations, and ensure that
your implementation compiles without warnings
* under Java 1.6.
*
* Name it {@link AppleExercise.Problem1.SingletonCache}
*/
/**
* Problem 1.2
*
* The HashMap class backing the {@link AppleExercise.Problem1.
SampleCache} class is not thread-safe.
* Duplicate and modify your {@link AppleExercise.Problem1.
SingletonCache} implementation to ensure
* that both Cache.put and Cache.get methods are safe to be called
by multi-threads.
* Do not use any @SuppressWarnings annotations, and ensure that
your implementation compiles
* without warnings under Java 1.6.
*
* Name it {@link AppleExercise.Problem1.ThreadSafeCache}
*/
/**
* Problem 1.3
*
* Use Java Generics to implement a non-singleton GenericCache class
to improve compile-time type checking.
*
* Name it {@link AppleExercise.Problem1.GenericCache}
*/
}
/**
* Using any Java 1.6 classes or language features, implement these five
methods.
* Create any helper classes or methods that you think contribute to an
elegant and
* efficient solution.
*
* If you feel like there is more than one solution to the problem,
* implement only the one that you feel is "best", and please explain
* why you think it is a better choice than the alternatives.
* List any assumptions that you made for your best solution.
*/
public static class Problem2 {
/**
* Problem 2.1
*
* Return an Iterator that iterates through of each String in the
order that they are provided,
* but skips {@code null} values.
*
* @param strings an array of nullable values
* @return an iterator of strings
*/
public static Iterator iterateStrings(String... strings) {
// TODO
return null;
}
/**
* Problem 2.2
*
* Return a single Iterator that chains together the array
of Iterators in the order
* that they are provided, but skips {@code null} values.
*
* @param stringIterators an array of nullable {@code Iterator<
String>}s of nullable {@code String}s
* @return an {@link java.util.Iterator} of {@code String}s
*/
public static Iterator iterateStrings(Iterator...
stringIterators) {
// TODO
return null;
}
/**
* Problem 2.3
*
* Return an Iterator that iterates through strings of each String[]
in the order that they are
* provided, but skips {@code null} values.
*
* @param stringArrays an array of nullable {@code String[}s of
nullable {@code String}s
* @return an {@link java.util.Iterator} of {@code String}s
*/
public static Iterator iterateStrings(String[]...
stringArrays) {
// TODO
return null;
}
/**
* Problem 2.4
*
* Return an Iterator that iterates through all Integers within each
two-dimensional Integer array in
* the order that they are provided, but skips {@code null} values.
*
* @param twoDimensionalIntArrays an array of nullable {@code
Integer[][]}s of nullable values
* @return an {@link java.util.Iterator} of {@code Integer}s
*/
public static Iterator iterateInts(Integer[][]...
twoDimensionalIntArrays) {
// TODO
return null;
}
/**
* Problem 2.5
*
* Return an Iterator that iterates through all Integers within each
set in the order that they are
* provided, but skips {@code null} values.
*
* @param integerSetList a list of nullable {@code LinkedHashSet}s
of nullable {@code Integer}s
* @return an {@link java.util.Iterator} of {@code Integer}s
*/
public static Iterator iterateInts2(ListInteger>> integerSetList) {
// TODO
return null;
}
/**
* Problem 2.6
*
* Bonus question!
*
* Despite using generics, invoking one of the methods above in
Problem 2 is not guaranteed to be
* type-safe.
*
* Answer the following questions:
*
* a) Which method is it?
*
* b) Does the java compiler let you know? If not, how can you
tell? If so, what warning or error
* will the compiler give you?
*
* c) What can you do to avoid the problem?
*/
}
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。