Hi,
I come across the term "type checking" very often in my readings on C++, and
have never heard it in Java. Besides the simplistic answer that it checks
the "type", what more does it mean?
WD
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.grisoft.com).
Version: 6.0.504 / Virus Database: 302 - Release Date: 24/07/2003 6 14290
"Web Developer" <no****@hotmail.com> wrote in message
news:3f********@news.iprimus.com.au... Hi,
I come across the term "type checking" very often in my readings on C++,
and have never heard it in Java. Besides the simplistic answer that it checks the "type", what more does it mean?
WD
I think its a question of timing. All languages check types, you aren't
allowed to multiply two strings in any language (AFAIK). But some languages
delay type checking until the program runs. C++ does most of its type
checking at compile type. This results in faster code, smaller data and
quicker detection of type errors, but it also means a more complex language.
We say C++ is a strongly typed language. In general I would say strong
typing is a good thing but there are occasions where you want to relax it
and check types at run time. That's where virtual functions and RTTI come
in.
john
On Mon, 11 Aug 2003 05:20:48 -0400, "ghl" <gl*******@comcast.net> wrote: "John Harrison" <jo*************@hotmail.com> wrote in message news:bh************@ID-196037.news.uni-berlin.de... "Web Developer" <no****@hotmail.com> wrote in message news:3f********@news.iprimus.com.au... > Hi, > > I come across the term "type checking" very often in my readings on C++, and > have never heard it in Java. Besides the simplistic answer that itchecks > the "type", what more does it mean? > > > WD >
I think its a question of timing. All languages check types, you aren't allowed to multiply two strings in any language (AFAIK). But some
languages delay type checking until the program runs. C++ does most of its type checking at compile type. This results in faster code, smaller data and quicker detection of type errors, but it also means a more complex language. We say C++ is a strongly typed language. In general I would say strong typing is a good thing but there are occasions where you want to relax it and check types at run time. That's where virtual functions and RTTI come in.
Java is also a strongly typed language and checks for compatible types for method arguments and return values at compile time.
Nope. Consider classes A, B and C in separate files, where A uses B uses
C, and A is the "main" program. Compile all. Change C to be incompatible
with B. Compile class A using Sun's compiler: no errors reported. Run.
Runtime error.
That could not happen in C++.
C++ has _global_ static type checking; Java has runtime type checking.
On Mon, 11 Aug 2003 13:34:20 GMT, to********@hotmail.com (tom_usenet) wrote: On Mon, 11 Aug 2003 10:23:27 GMT, al***@start.no (Alf P. Steinbach) wrote:
Nope. Consider classes A, B and C in separate files, where A uses B uses C, and A is the "main" program. Compile all. Change C to be incompatible with B. Compile class A using Sun's compiler: no errors reported. Run. Runtime error.
That could not happen in C++.
C++ has _global_ static type checking; Java has runtime type checking. The Java language has stronger static type checking than C++. e.g. implicit conversions from double to int, etc. don't exist. C++ however has better idioms for static type checking, thanks to using generics rather than an Object base-of-all class. Java encourages use of the evil instanceof operator.
I think you're talking about the link time safety that C++ has thanks to name mangling. But C++ will just crash if you replace a DLL with another one with incompatible types, so I don't get your point.
DLLs are not part of C++.
Java will detect the problem if you recompile
Nope. Java will only detect the problem if you recompile class B.
You have an executable system without recompiling class B (and this is
not theoretical, it has been a major problem in some large Java projects).
just as happens with C++.
Nope. With C++ you have global type-checking. You cannot obtain an
executable with static type inconsistencies.
"Alf P. Steinbach" <al***@start.no> wrote in message
news:3f****************@News.CIS.DFN.DE... On Mon, 11 Aug 2003 05:20:48 -0400, "ghl" <gl*******@comcast.net> wrote:
"John Harrison" <jo*************@hotmail.com> wrote in message news:bh************@ID-196037.news.uni-berlin.de... "Web Developer" <no****@hotmail.com> wrote in message news:3f********@news.iprimus.com.au... > Hi, > > I come across the term "type checking" very often in my readings on
C++, and > have never heard it in Java. Besides the simplistic answer that it
checks > the "type", what more does it mean? > > > WD >
I think its a question of timing. All languages check types, you aren't allowed to multiply two strings in any language (AFAIK). But some languages delay type checking until the program runs. C++ does most of its type checking at compile type. This results in faster code, smaller data and quicker detection of type errors, but it also means a more complex language. We say C++ is a strongly typed language. In general I would say strong typing is a good thing but there are occasions where you want to relax
it and check types at run time. That's where virtual functions and RTTI
come in.
Java is also a strongly typed language and checks for compatible types
formethod arguments and return values at compile time.
Nope. Consider classes A, B and C in separate files, where A uses B uses C, and A is the "main" program. Compile all. Change C to be incompatible with B. Compile class A using Sun's compiler: no errors reported. Run. Runtime error.
Wrong. Been there. Tried that.
Created classes as above, all returning String type reference variable.
Changed return type of C to int. Message on recompiling A gives:
..\C.java:3: incompatible types
found : java.lang.String
required: int
public int info = "I'm c";
^
..\C.java:13: incompatible types
found : int
required: java.lang.String
return info;
^
2 errors
--
Gary
"Alf P. Steinbach" <al***@start.no> wrote in message
news:3f****************@News.CIS.DFN.DE... On Mon, 11 Aug 2003 13:06:42 -0400, "ghl" <gl*******@comcast.net> wrote:
"Alf P. Steinbach" <al***@start.no> wrote in message news:3f****************@News.CIS.DFN.DE...
<<large snip>> "Change" means: change the source code of class C, compile class C.
Then compile class A, or not (it makes no difference), and run:
Exception in thread "main" java.lang.NoSuchMethodError:
C.result()Ljava/lang/String; at B.result(B.java:5) at A.main(A.java:5)
Got it?
Ah, I get what you're driving at. Yes, you get that. Does the same thing
happen in C++ with the linker detecting the change?
The Java error at runtime is detected because there is no linker and the
type checking can only occur when class C is actually loaded and checked.
I get your point.
--
Gary
On Mon, 11 Aug 2003 13:36:19 -0400, "ghl" <gl*******@comcast.net> wrote: "Alf P. Steinbach" <al***@start.no> wrote in message news:3f****************@News.CIS.DFN.DE... On Mon, 11 Aug 2003 13:06:42 -0400, "ghl" <gl*******@comcast.net> wrote:
>"Alf P. Steinbach" <al***@start.no> wrote in message >news:3f****************@News.CIS.DFN.DE... <<large snip>> "Change" means: change the source code of class C, compile class C.
Then compile class A, or not (it makes no difference), and run:
Exception in thread "main" java.lang.NoSuchMethodError: C.result()Ljava/lang/String; at B.result(B.java:5) at A.main(A.java:5)
Got it?
Ah, I get what you're driving at. Yes, you get that. Does the same thing happen in C++ with the linker detecting the change?
In practice the linker detects the change, yes.
In theory there need not be a linker in a C++ implementation, but the
_language_ (standard) guarantees global static type-checking whatever
execution system is actually used.
There's no runtime error because you don't get an executable. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: dmgauntt2002 |
last post by:
I have some javascript ASP code that sets the expiry date on a cookie
to five years from now. The code worked until today, when I got the
following error message:
Microsoft JScript runtime...
|
by: Andrew Proctor |
last post by:
Hello
This is not a big problem, but I was hoping someone a bit more
knowlegable than I could explain something to me.
I have a simple function behind a form which writes changed values to
a...
|
by: Dave |
last post by:
How do I check in a Windows Forms app if any controls have changed? I have
a form that collects data, and I want to prompt the user if they try to exit
the app, or load a new file, without saving...
|
by: Jon |
last post by:
I'm learning about datatables. When using the example provided by MS in the
..NET Framework Class Library for DATATABLE (see below) I get an error on line
3 that says "Type expected". Is something...
|
by: Geoff Jones |
last post by:
Hi
I'm trying to use a class that I've written in a form. Unfortunately, when I
write something like:
Public x As New myClass
I get the compile time error: "Type Expected". Indeed, the...
|
by: Phill. W |
last post by:
In a ListView Control, you can type in a short prefix and the
ListView scrolls to the next Item matching that prefix.
Is there anyway to make processing this work with a Subitem?
I can sort...
|
by: Nie longhai |
last post by:
I have a generic method in a class as follow:
T Get<T>(string key)
{
.....
return Convert.ChangeType(v, typeof(T))
}
when I use it in my code:
|
by: Diwa |
last post by:
Does the "value" type (value as in key-value pair )of "std::map"
require a default ctor even if it is not used ?
If I comment out Line 1 in the code attached later,
i.e remove the default ctor...
|
by: Davros9 |
last post by:
Trying to get Regular Expressions working.......
----------------
Public Function SepString(InField As String) As String
''seperates on space and comma
Dim RE As New RegExp
Dim Matches As...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |