class A {public:virtual string foo(){return "A::foo";}};
class B : public A {public:virtual string foo(){return "B::foo";}};
int main () {B* b = new B();// In my opinion the following should not be allowedcout << b->A::foo() << endl; // Will print "A::foo"}
$ bc -lq12^34520774466823273785598434446955827049735727869127052322369317059031795\19704325276892191015329301807037794598378537132233994613616420526484\93077727371807711237016056649272805971389591721704273857856298577322\13812114239610682963085721433938547031679267799296826048444696211521\30457090778409728703018428147734622401526422774317612081074841839507\864189781700150115308454681772032
create table wtf (key number primary key, animal varchar2(10));insert into wtf values (1,'dog');insert into wtf values (2,'');insert into wtf values (3,'cat');select * from wtf where animal <> 'cat';
package Employee;our @ISA = qw(Person);# somwhere far far away in a package long ago@Employee::ISA = qw(Shape);# Now all Employee objects no longer inherit from 'Person' but from 'Shape'
For i As Integer = 1 to 10 ... NextWhile True ... End WhileDo While True ... LoopDo Until True ... LoopDo ... Loop While TrueDo ... Loop Until TrueWhile True ... Wend
Integer foo = 1000;Integer bar = 1000;
foo <= bar; // truefoo >= bar; // truefoo == bar; // false
//However, if the values of foo and bar are between 127 and -128 (inclusive)//the behaviour changes:
Integer foo = 42;Integer bar = 42;
foo <= bar; // truefoo >= bar; // truefoo == bar; // true
补充说明
快速浏览Java源代码将出现以下内容:
/*** Returns a <tt>Integer</tt> instance representing the specified* <tt>int</tt> value.* If a new <tt>Integer</tt> instance is not required, this method* should generally be used in preference to the constructor* {@link #Integer(int)}, as this method is likely to yield* significantly better space and time performance by caching* frequently requested values.** @param i an <code>int</code> value.* @return a <tt>Integer</tt> instance representing <tt>i</tt>.* @since 1.5*/public static Integer valueOf(int i) {if (i >= -128 && i <= IntegerCache.high)return IntegerCache.cache[i + 128];elsereturn new Integer(i);}
备注:IntegerCache.high默认为127,除非由属性设置。
自动装箱的情况是,foo和bar都是从缓存中检索到的同一个整数对象,除非显式创建:例如foo = new Integer(42),因此在比较引用相等性时,它们将是true而不是false。比较整数值的正确方法是使用.equals;
$a = 'Juliet';$$a = 'awesome'; // assigns a variable named $Juliet with value 'awesome'
echo '$a'; // prints Julietecho '${$a}'; // prints awesomeecho '$Juliet'; // prints awesome
switch (someInt) {case 1:case 2: System.out.println("Forgot a break, idiot!");case 3: System.out.println("Now you're doing the wrong thing and maybe need hours to find the missing break muahahahaha");break;default: System.out.println("This should never happen -,-");}
With xml.appendChild(xml.createElement("category")).setAttribute("id",id).setAttribute("keywords",keywords)With .appendChild(xml.createElement("item")).setAttribute("count",count).setAttribute("tip",tip).appendChild(xml.createTextNode(text))End WithEnd With
>>> a[0] = "hello"NameError: name 'a' is not defined>>> a[0:] = "hello"NameError: name 'a' is not defined>>> a = []>>> a[0] = "hello"IndexError: list assignment index out of range>>> a[0:] = "hello">>> a['h', 'e', 'l', 'l', 'o']
$ a=3$ echo $a3$ echo ${a[@]} # treat it like an array3$ declare -p a # but it's notdeclare -- a="3"$ a[1]=4 # treat it like an array$ echo $a # acts like it's scalar3$ echo ${a[@]} # but it's not3 4$ declare -p adeclare -a a='([0]="3" [1]="4")'$ a=5 # treat it like a scalar$ echo $a # acts like it's scalar5$ echo ${a[@]} # but it's not5 4$ declare -p adeclare -a a='([0]="5" [1]="4")'
ksh做同样的事情,但使用typeset而不是declare。
当你在zsh中执行此操作时,你会得到子字符串赋值而不是数组:
$ a=3$ a[2]=4 # zsh is one-indexed by default$ echo $a34$ a[3]=567$ echo $a34567$ a[3]=9$ echo $a34967$ a[3]=123 # here it overwrites the first character, but inserts the others$ echo $a3412367$ a=(1 2 3)$ echo $a1 2 3 # it's an array without needing to use ${a[@]} (but it will work)$ a[2]=99 # what about assignments?$ echo $a1 99 3
a_function(SomeVariable) ->statements_end_with_commas(),case PatternMatching of0 -> now_we_end_with_semicolon;true -> except_the_last_oneend.
%% Function definitions end with periods!
-- Create a function that returns a Maybe Int, and return a 5, which know is definitly Int'able> let x :: Maybe Int; x = 5;<interactive>:1:24:No instance for (Num (Maybe Int))arising from the literal `5' at <interactive>:1:24Possible fix: add an instance declaration for (Num (Maybe Int))In the expression: 5In the definition of `x': x = 5
> Just 5Just 5it :: Maybe Integer
-- Create a function x which takes an Int> let x :: Int -> Int; x _ = 0;x :: Int -> Int-- Try to give it a Just Int> x $ Just 5
<interactive>:1:4:Couldn't match expected type `Int' against inferred type `Maybe t'In the second argument of `($)', namely `Just 5'In the expression: x $ Just 5In the definition of `it': it = x $ Just 5
class Foo{private $var = 'avalue';
private function doStuff(){return "Stuff";}
public function __get($var){return $this->$var;}
public function __call($func, array $args = array()){return call_user_func_array(array($this, $func), $args);}}
$foo = new Foo;var_dump($foo->var);var_dump($foo->doStuff());
Fatal error: Call to private method Foo::doStuff() from context ”.”
我认为这些在C风格语言中很多都可以工作,但我不确定。
将here文档作为函数参数传递:
function foo($message){echo $message . "\n";}
foo(<<<EOFLorem ipsum dolor sit amet, consectetur adipiscing elit. Nuncblandit sem eleifend libero rhoncus iaculis. Nullam eget nisi atpurus vestibulum tristique eu sit amet lorem.EOF);
mysql> CREATE TEMPORARY TABLE Foo (name varchar(128) NOT NULL);DESCRIBE foo;ERROR 1146 (42S02): Table 'foo' doesn't existmysql> DESCRIBE Foo;+-------+--------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+-------+--------------+------+-----+---------+-------+| name | varchar(128) | NO | | NULL | |+-------+--------------+------+-----+---------+-------+1 row in set (0.06 sec)mysql> INSERT INTO Foo (`name`) VALUES ('bar'), ('baz');Query OK, 2 row affected (0.05 sec)
mysql> SELECT * FROM Foo WHERE name = 'BAR';+------+| name |+------+| bar |+------+1 row in set (0.12 sec)
mysql> SELECT * FROM Foo WHERE name = 'bAr';+------+| name |+------+| bar |+------+1 row in set (0.05 sec)
void foo() {int int_inst;
// usual style - brackets ...size_t a = sizeof(int);size_t b = sizeof(int_inst);size_t c = sizeof(99);
// but ...size_t d = sizeof int_inst; // this is ok// size_t e = sizeof int; // this is NOT oksize_t f = sizeof 99; // this is also ok}
var d = new Date("1/1/2001");
var wtfyear = d.getYear(); // 101 (the year - 1900)// to get the *actual* year, use d.getFullYear()
var wtfmonth = d.getMonth(); // 0// months are 0-based!
在Python中,C三元运算符(C++例子:bool isNegative = i < 0 ? true : false;)可用作语法糖:
>>> i = 1>>> "It is positive" if i >= 0 else "It is negative!"'It is positive'>>> i = -1>>> "It is positive" if i >= 0 else "It is negative!"'It is negative!'
这不是很奇怪,而是一个特性。奇怪的是与C(CONDITION? A: B)中的(IMO更合乎逻辑的)顺序相比,改变了顺序(A if CONDITION else B)。
在scala中,没有运算符,只有方法。所以a + b - c实际上与a.+(b).-(c)相同。在这种情况下,它等于Smalltalk。然而,与Smalltalk不同的是,优先级被考虑在内。规则基于第一个字符,因此名为*+的假设方法将优先于名为+*的方法。做了一个例外,以便任何以=结尾的方法都将具有与==相同的优先级--这意味着!!和!=(非假设方法)具有不同的优先级。
所有ASCII字母的优先级都最低,但所有非ASCII(Unicode)字符的优先级都最高。因此,如果您编写了一个比较两个整数的方法is,那么2 + 2 is 1 + 3将编译并为真。如果您用葡萄牙语编写它,é,那么2 + 2 é 1 + 3将导致错误,因为它会将其视为2 + (2 é 1) + 3。
Chomsky is a room.A thought is a kind of thing.Color is a kind of value.The colors are red, green and blue.A thought has a color. It is usually Green.A thought can be colorful or colorless. It is usually colorless.An idea is a thought in Chomsky with description "Colorless green ideas sleep furiously."A manner is a kind of thing.Furiously is a manner.Sleeping relates one thought to one manner.The verb to sleep (he sleeps, they sleep, he slept, it is slept, he is sleeping) implies the sleeping relation.Colorless green ideas sleep furiously.
A : Base class, e.g. "Object"AProxy: Base class, constructs with other A to bind toB : derives from AC : derives from AProxyD : derives from both B and C (passing B's A to C's AProxy at construction)
class Base {protected:m_fooBar;};
class Derived: public Base {public:void Test(Base& baseInstance) {m_fooBar=1; //OKbaseInstance.m_fooBar = 1; //Badness//This, however is OK:((Derived&)baseInstance).m_fooBar = 1; //OK}};
[2*2] = 5
[Здравствуй, мир!] = [Hello, world!]
[] = "Looks like my name is an empty string, isn't that cool?"
For[For[i=0]=[0]To[To[To[0][Next[To]([For[i=0])=[For[i=0]Next
String a = "Hello";String b = "Hello";System.out.println(a == b ); // prints true.String c = new String("Hello");String d = new String("Hello");System.out.println(c == d ); // prints false
var something = 12;
function nicelyCraftedFunction(){something = 13;// ... some other code// ... and in Galaxy far, far away this:if( false ) // so the block never executes:{var something;}}nicelyCraftedFunction(); // call of the function
for n in range(2, 10):for x in range(2, n):if n % x == 0:print n, 'equals', x, '*', n/xbreakelse:# loop fell through without finding a factorprint n, 'is a prime number'
输出:
2 is a prime number3 is a prime number4 equals 2 * 25 is a prime number6 equals 2 * 37 is a prime number8 equals 2 * 49 equals 3 * 3
$a = 07; // 7 (as it should be)$b = 08; // 0 (would be an error in any sensible language)$c = 018; // 1 (again, should have been an error)$d = 0A; // error (as it should be)
PS> $a = "4" # stringPS> $a * 3 # Python can do this, too444PS> 3 * $a # Python doesn't do it this way, string repetition is commutative12PS> $a + 3 # Python gives a mismatched types error43PS> 3 + $a # Python would give an error here, too7
public class Animal{public virtual string Speak() { return "unknown sound" ; }}
public class Dog : Animal{public override string Speak() { return "Woof!" ; }}
struct S{S() {} //default constructor};
int main() {
S s(); // this is not a default construction, it declares a function named s that takes no arguments and returns S.}