Assuming that you have a lot of classes that extends the class Base.  class Base{}  class A extends Base[}  class B extends Base{}  class C extends Base{}   What must I write so that when I write a get method, I will get the class that I want?  public Base get(Class &lt;? extends Base&gt; clazz, final String key){     //not important. }   I want the method to return Objects of class A, B, or C, depending on the input clazz.
Consider this example (typical in OOP books):    I have an Animal class, where each Animal can have many friends. And subclasses like Dog, Duck, Mouse etc which add specific behavior like bark(), quack() etc.  Here's the Animal class:  public class Animal {     private Map&lt;String,Animal&gt; friends = new HashMap&lt;&gt;();      public void addFriend(String name, Animal animal){         friends.put(name,animal);     }      public Animal callFriend(String name){         return friends.get(name);     } }   And here's some code snippet with lots of typecasting:  Mouse jerry = new Mouse(); jerry.addFriend("spike", new Dog()); jerry.addFriend("quacker", new Duck());  ((Dog) jerry.callFriend("spike")).bark(); ((Duck) jerry.callFriend("quacker")).quack();   Is there any way I can use generics for the return type to get rid of the typecasting, so that I can say      jerry.callFriend("spike").bark(); jerry.callFriend("quacker").quack();   Here's some initial code with return type conveyed to the method as a parameter that's never used.   public&lt;T extends Animal&gt; T callFriend(String name, T unusedTypeObj){     return (T)friends.get(name);         }   Is there a way to figure out the return type at runtime without the extra parameter using instanceof? Or at least by passing a class of the type instead of a dummy instance. I understand generics are for compile time type-checking, but is there a workaround for this?
How do I echo and send console output to a file in a bat script? Spurious space above align environment at top of page/minipage It seems that the align environment adds additional vertical space if it starts at the top of a page or minipage.  Below are two pages, and two minipages (on Page 1), where the first page/minipage has text followed by an align* environment, and the second page/minipage starts with an align* environment, and note that the equations are still aligned.  Attempted Solution: The closest related question I found was:    I attempted to use the  at the above by adding \setlength\abovedisplayskip{0pt} (after the preamble as per ).  Although, this did move the equations up vertically, they were still vertically aligned:  And since the problem occurs at top of a page as well, I don't think this is related to  Question:  How can I adjust the align environment to automagically not have additional space at the top of a page or minipage? Is there a reason for this behavior, and perhaps should not be changed?  Code: \documentclass{article} \usepackage[showframe,paperwidth=3.5in,paperheight=2.2in,margin=0.5in]{geometry} \usepackage{amsmath}  \begin{document}%\setlength\abovedisplayskip{0pt} Top of Page 1 \begin{align*}% Text above at top of page  e &amp;= m c^2 \end{align*}  \hrule \begin{minipage}[t]{0.45\linewidth}     Top of minipage 1     \begin{align*}% Text above this minipage      e &amp;= m c^2     \end{align*} \end{minipage} \begin{minipage}[t]{0.45\linewidth}     \begin{align*}% No text above in this minipage      e &amp;= m c^2     \end{align*} \end{minipage}  \newpage \begin{align*}% No text above at top of page  e &amp;= m c^2 \end{align*} \end{document} How can native English speakers read an unknown word correctly? R stem and leaf values How to make a stem and leaf plot with the following data in "R":  1717 1719 1645 3739 3024 3664 3830 2991 2430 2730 3469 5086 2119 3021 3292 2844 3426 2067 3215 2767 3124 2573 2840 2449 2584 1505 1390 1645 2497 3466 3228 3192  The only way to get a reasonable amount of stems is to make the stem the first digit in each number and the leaves will all be 3 digit numbers. I am not able to split the data in this way, R represents the stem with 1 digit but round my numbers  so 2584 is shown as 2| 5 (3 decimals to the right) which would be 2500. How do I adjust my stem and leaf numbers? How do I resolve these unmet dependencies? Finite group for which $|\{x:x^m=e\}|\leq m$ for all $m$ is cyclic. Let $G$ be a finite group. For each positive integer $m$, if $x^{m}=e$ has at most $m$ solutions in $G$, $G$ is cyclic.   What I have thought is that $n=\sum_{d\mid n}\phi(d)$ can be used to solve this and showing that $|G|$ order element in $G$ exists is enough. I am looking to use this feature for two purposes: scanning books (one camera pointed at each of a pair of pages), and for stereo 3D photography.  I would like to be able to preview and capture photos from two cameras simultaneously, and download them to my Mac (recent laptop, Mac OS X 10.8.x). Being able to keep track of which photos were from which camera is also a must.  I see a couple of packages that will do this via USB tethering on Windows, namely  (which other than being on Windows, looks perfect for my needs) and . I certainly could run Windows on my Mac somehow, but I'd rather avoid that, if possible.  I haven't bought the cameras yet, and I do not have any requirements as to which cameras are supported (it seems the packages above only support Canons), other than that they be relatively inexpensive. This is a hobby-type project, not a $3000 dSLR-type project.  However, even if all you have is a dSLR solution for this problem, I'd still like to hear about it. Perhaps it will lead to related solution.  Inventive hacky solutions welcome! How to close view windows? I would like to close some view windows that I opened accidentally.  See the image below:    Edit: another note: I tried searching for the solution, but only found things like "Join Area", which don't seem to work in this situation. Identity involving Euler's totient function: $\sum \limits_{k=1}^n \left\lfloor \frac{n}{k} \right\rfloor \varphi(k) = \frac{n(n+1)}{2}$ Let $\varphi(n)$ be Euler's totient function, the number of positive integers less than or equal to $n$ and relatively prime to $n$.    Challenge: Prove  $$\sum_{k=1}^n \left\lfloor \frac{n}{k} \right\rfloor \varphi(k) = \frac{n(n+1)}{2}.$$   I have two proofs, one of which is partially combinatorial.    I'm posing this problem partly because I think some folks on this site would be interested in working on it and partly because I would like to see a purely combinatorial proof.  (But please post any proofs; I would be interested in noncombinatorial ones, too.  I've learned a lot on this site by reading alternative proofs of results I already know.)  I'll wait a few days to give others a chance to respond before posting my proofs.  EDIT: The two proofs in full are now given among the answers. How do I create a master workbook in excel? In powerpoint we have something called a master slide.  I want the same idea for excel.  I want to create a template that I can work on with formulas and I want it to update all children files.  Example: I have a budget template.  This template has a budget listing all required equipments and their cost for a project.  We then have a formula that calculates the total cost of all equipment. I want to update only the template file with equipment and formulas, but I want the actual files (children) to contain the costs (because they might be different costs for different locations, but the rest of the budget and its formulas are shared).  Its pretty much exactly what a master slide in powerpoint is, if you've ever used that you should understand what I'm trying to do pretty easily.  One master file to store formulas, and a bunch of children files that store the data to be accessed by those formulas.  This way if a formula needs to be changed, the templates is adjusted and all other files update accordingly.  Any ideas?  I'd prefer not to have to use VB, and I'd also like a solution that works for both mac and windows.  Found  question but no answers.  I've already created a template, but that doesn't seem to update the other files when I modify it. How does the versioning work here? How does SO's (or other SE sites) versioning work of questions and answers? Do they use some standard piece of code or is it something homebrew?  With versioning I meant if for example a question is edited you'll see all the changes (a diff). Showing there is no ring whose additive group is isomorphic to $\mathbb{Q}/\mathbb{Z}$ What was Tauriel doing during the events of The Lord of the Rings movies? [Yes, The Hobbit movies are nonsense. But how could I call myself a fantasy fan if I didn't demand my nonsense be as logical as possible?]  Tauriel is presented as a highly-skilled fighter and a combatant for the side of good. Despite this, she apparently did nothing during Sauron's war on the free peoples.  Was she somehow     still mourning Killi, after all these decades?   Was she dead? Or is there another reason she didn't participate? Async call generates " Error: Can't wait without a "fiber", even with _wrapAsync Cu has an unpaired electron in 4s, but it is diamagnetic. I thought that it has to be paramagnetic. What am I missing? I know that contents of double quotes are expanded, whereas the contents of single quotes are not, such that  echo '$1'   gives  $1   where as   echo "$1"   gives  &lt;the argument - blank in this particular example&gt;   the same as   echo $1   However, the question  led me to wonder why double quotes and not single quotes were used when declaring the alias, thus:  alias cutf="_cutf"   instead of   alias cutf='_cutf'   I would have employed single quotes as in the latter example. Most examples on the web use single too, unless there is some expansion required. However, in this case, no expansion, to my eyes, is apparent. Is it that, in this case, they are interchangeable, or are the double quotes necessary because a function definition is employed? How to persistently control maximum system resource consumption on Mac? Before Mavericks, I could use /etc/launchd.conf file to change maximum system resource consumption, for example:  limit maxfiles 16384 unlimited limit maxproc 16384 unlimited   It no longer works in Mavericks.  What is the correct way to do it in the recent version of OS X? If $\int_0^x f \ dm$ is zero everywhere then $f$ is zero almost everywhere I have been thinking on and off about a problem for some time now. It is inspired by an exam problem which I solved but I wanted to find an alternative solution. The object was to prove that some sequence of functions converges weakly to zero in $L^2$.   I managed to show (with some help) that the limit $f$ (of a subsequence) satisfies $\int_0^x f \ dm=0$ for all $x&gt;0 $. From this I want to conclude that $f=0$ a.e. I can do this with the fundamental theorem of calculus in its Lebesgue version but there ought to be a more elementary proof.  Can someone here help me out? Are there any advanced options for Google Chrome's history search? How can I find the version of Ubuntu that is installed? I installed some version of Ubuntu on my VMware, but I don't know what version exactly it is. How can I find it out?